Additional Services

How to Automatically Convert a Document to PDF

Updated: October 16, 2020

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.


We'd love to hear your thoughts!

All fields required