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 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"