Nuxeo Server

How to Automatically Convert a Document to PDF

Updated: December 5, 2017 Page Information Edit on GitHub

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, two options are available:

  • Use the default File document type, in that case, the metadata that holds the blob is file:content.
  • Define your own custom metadata to store the blob. To do so, you first need to add a field to the schema in the document definition. This new metadata has to be a 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 "Blob 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 (or to use a context variable).

For the same reasons, we also do not want to lose 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:

- Context.FetchDocument
- Context.PushDocument
- Blob.ToPDF
- Context.SetInputAsVar:
    name: pdfblob
- Context.PopDocument
- Document.SetBlob:
    file: "@{Context[\"pdfblob\"}"
    save: "true"
    xpath: "myDocumentSchema:pdffile"

5 days ago Manon Lumeau add tags for doc days
25 days ago GitHub NXDOC-1362 Fix automation chain sample
a month ago manonlumeau Added content-review-lts2017 label
2 months ago manonlumeau NXDOC-1346-FT review screenshot
2 years ago Manon Lumeau 24
2 years ago Manon Lumeau 23
3 years ago Solen Guitter 22
3 years ago Solen Guitter 21
3 years ago Manon Lumeau 20
3 years ago Manon Lumeau 18
3 years ago Manon Lumeau 19
3 years ago Manon Lumeau 17
3 years ago Solen Guitter 16
3 years ago Solen Guitter 15
3 years ago Solen Guitter 14
4 years ago Alain Escaffre 13
4 years ago Solen Guitter 12 | Added excerpt
5 years ago Solen Guitter 10
5 years ago Solen Guitter 11 | Migrated to Confluence 4.0
6 years ago Solen Guitter 9
6 years ago Solen Guitter 8 | added related howtos
6 years ago Alain Escaffre 7
6 years ago Frédéric Vadon 6
6 years ago Frédéric Vadon 4
6 years ago Frédéric Vadon 5
6 years ago Frédéric Vadon 1
6 years ago Frédéric Vadon 2
6 years ago Frédéric Vadon 3
History: Created by Frédéric Vadon