Additional Services

How to Automatically Convert a Document to PDF

In some cases, you want the system to automatically create a PDF conversion of a document and attach it to the document. In Nuxeo Studio, the operation Conversion > Convert to PDF is provided to make this conversion.

Here is how you can create an automation chain to do the conversion and attach the PDF created on the input document.

This how to requires knowledge about:

Document Preparation

The document needs a metadata to hold the PDF blob created during the conversion. So, on the document definition, we first need to add a field to the schema. This new metadata has to be of Blob type.

Here is an example where the new metadata is "pdffile". It can be accessed by "myDocumentSchema:pdffile" if the schema name of my document type is "myDocumentSchema".

Automation Chain

The "convert to pdf" operation accepts either blob, bloblists or document as inputs. If the input is a document, the file to convert must be in the file:content metadata (the usual place for it). The operation produces a blob (the PDF file) and does not return the input document so we will have to store the document somehow before the conversion so that we can recall it after to attach the PDF file to it. The solution is to use Push & Pop operation to put the input document in a heap and get it back.

For the same reasons, we also do not want to loose the PDF file produced by the conversion during the recall of the input document, so we will save it as a Context variable.

The automation chain to configure is finally:

  • Fetch > Context Document
  • Push & Pop > Push Document
  • Conversion > Convert to pdf
  • Execution Context > Set Context Variable From Input (name:pdfblob)
  • Push & Pop > Pop Document
  • Document > Set File (file: @{Context["pdfblob"]}; save: checked; xpath: myDocumentSchema:pdffile)

In step 3 we call the subchain that operates the PDF conversion. This automation chain can be set as standalone chain and called from other chains (Execution Flow > Run Operation) or directly included in another automation chain.

 


4 months ago Andrew Goodricke Updated for 10.10
4 years ago Solen Guitter 22
4 years ago Solen Guitter 21
5 years ago Manon Lumeau 20
5 years ago Manon Lumeau 18
5 years ago Manon Lumeau 19
5 years ago Manon Lumeau 17
5 years ago Solen Guitter 16
5 years ago Solen Guitter 15
5 years ago Solen Guitter 14
5 years ago Alain Escaffre 13
6 years ago Solen Guitter 12 | Added excerpt
7 years ago Solen Guitter 10
7 years ago Solen Guitter 11 | Migrated to Confluence 4.0
8 years ago Solen Guitter 9
8 years ago Solen Guitter 8 | added related howtos
8 years ago Alain Escaffre 7
8 years ago Frédéric Vadon 6
8 years ago Frédéric Vadon 4
8 years ago Frédéric Vadon 5
8 years ago Frédéric Vadon 1
8 years ago Frédéric Vadon 2
8 years ago Frédéric Vadon 3
History: Created by Frédéric Vadon

We'd love to hear your thoughts!

All fields required