Please enable JavaScript to view this site.

InterFormNG2 Manual

Navigation: Workflow > Workflow examples

Workflow: Create PDF and insert it as base64

Scroll Prev Top Next More

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