Workflow: Create PDF and insert it as base64

Workflow: Create PDF and insert it as base64

In the section below you can see how you can setup the workflow in InterFormNG2 to create a PDF file and insert it into the input XML file encoded in base64.

 

The complete workflow looks like below:

 

First part:

 

NGWorkflowExampleBase64_0001

 

Second part:

NGWorkflowExampleBase64_0002

 

Each of the component are described below in these 8 sections:

 

1.Reads an input XML file from a folder.

2.Stores the input XML file in a property named backupData.

3.Creates a PDF document and overwrites the XML in the payload with the PDF, that is the result of this merge.

4.The data of the PDF file is converted into base64 and the base64 data stream now replace the PDF in the payload.

5.The base64 payload is copied into a workflow variable named Base64.

6.The input XML file is retrieved into the payload again from the named property, backupData, which was saved in step 2.

7.The base64 data in variable Base64 is inserted into the input XML file via an xslt transformation.

8.The transformed XML file with the base64 data is saved to the file system.

 

 

Read an input XML file from a folder

This is defined via a new workflow with the read from file as input. In this example it looks like this:

 

NGWorkflowExampleBase64_0003

 

In this example we monitor the folder inbox_insert_base64 in the InterFormNG2 home directory.

 

 

Store the input file in a property named backupData

We keep a copy of the input file in a named property with the workflow component, payload to named property. In this case we use this setup:

 

NGWorkflowExampleBase64_0004

 

 

Create a PDF file in the payload

We use the Create PDF document component to create a PDF by merging the input XML with a template:

 

NGWorkflowExampleBase64_0005

 

 

Convert the PDF into base64

The PDF data stream is converted into base64 with the component, To base64, which has no parameters.

 

 

Copy Base64 Payload to a variable

The base64 payload is copied into a workflow variable, Base64 via the Payload to workflow variable component with this setting:

NGWorkflowExampleBase64_0006

 

 

Retrieve the input file from the named property

With the named property to payload component we can reload the input XML file into the payload like so:

NGWorkflowExampleBase64_0007

 

 

 

Insert base64 data stream into XML

The variable, Base64 contains the base64 datastream and that is inserted with the XSL transformation component, that in this case refers to a transformation file:

NGWorkflowExampleBase64_0008

 

The contents of the xslt file is this:

 

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:fn="http://www.w3.org/2005/xpath-functions">

<xsl:param name="Base64" />

  <xsl:template match="@* | node()">

     <xsl:copy>

        <xsl:apply-templates select="@* | node()"/>

     </xsl:copy>

  </xsl:template>

  <xsl:template match="/Root/CompanyInfo">

<xsl:copy>

     <xsl:copy-of select="node()"/>

     <PDF_Base64><xsl:value-of select="$Base64" /></PDF_Base64>

   </xsl:copy>

  </xsl:template>

</xsl:stylesheet>

 

This xslt defines the variable, Base64 and inserts the value into a new node named, PDF_Base64 in the path, /Root/CompanyInfo.

 

 

Save the XML to the file system

Finally the changed XML file is saved with the To filesystem component:

 

NGWorkflowExampleBase64_0009

    • Related Articles

    • Create PDF email

      This workflow component merges the input file with a template and sends out an email with an attachment PDF file, which is result of the merge between the input file and the template. The output payload is the same as the input payload e.g. XML. This ...
    • Create EML with PDF

      The create document, workflow component, Create EML with PDF is the same as the Create PDF email component with two major differences: The Create PDF email component sends out an email. The Create EML with PDF document creates an EML file in the ...
    • Advanced Create document workflow components

      The list of advanced create document workflow components is here: 1.Append a PDF. This appends (adds) an extra PDF file to the PDF file in the payload. This require the Advanced PDF module. 2.Create EML with PDF. This creates an email in the payload ...
    • Create PDF document

      With this workflow component you can merge an input file with a template (both InterFormNG2 and InterFormNG templates) to create the output stream in PDF format. This can later e.g. be sent to a (laser) printer, that supports PDF or as input for e.g. ...
    • Create PDF file

      The Create PDF file workflow component is found under Basic and create document. This component accepts an XML file as input. The component creates a PDF file and stores it directly in the file system. The output payload is the same as the input ...