An OL Connect print flow in Node-RED

This topic gives an overview of the nodes and files that are used in a typical OL Connect print flow in Node-RED.

An easy way to create some example files to work with is to use a Sample Project. There are two Sample Projects that create a sample print project; see Sample Projects. For a print flow in Node-RED you would use all files except the Workflow configuration file.

If the objective of the flow is to serve a preview of a PDF, take a look at this topic: An OL Connect preview PDF flow in Node-RED.

Tip: Example print flows are provided by OL Connect Automate, once installed. The examples appear in the flows folder in the Import dialog in Node-RED which allows you to import an example flow into a new or existing flow; see Importing and Exporting Flows in the Node-RED documentation. Instructions are given in the Comment node.

Alternatively, an easy way to get the files that the typical OL Connect print flow needs, is to use a Sample Project. There are two Sample Projects that create a sample print project; see Sample Projects. You would use all files except the Workflow configuration file.

The structure of a print flow

Generate paginated print output for XML data using the **all in one** node. This node extracts data from the data file, merges the data with a Connect Designer template, and creates print output.\n\nIn its simplest form, a print flow may consist of a node that captures a data file, such as a **folder capture** or **read file** node, the **all in one** node and a node to save the result to disk.

In its simplest form, a print flow may consist of a node that captures a data file, such as a folder capture node or read file node, the OL Connect all in one node, and a node to save the result to disk.

The all in one node combines the following four OL Connect nodes:

  • The data mapping node that extracts data from a file and stores a record set in the database, or the data get node that retrieves previously extracted data from the database.

    • The data mapping node needs a data mapping configuration, made with the DataMapper (see Data mapping configurations), and a data file of course.

    • All the data get node needs is a Record Set ID.

  • The paginated content node. This node merges the data with a template, resulting in Print Content Items. Templates are made with the Designer (see Templates).

  • The paginated job node. This node turns a set of Print Content Items into a print job. Any job settings are passed on via a Job Preset which is made with the Designer (see Job Creation Presets).

  • The paginated output node. This node creates the actual output file(s) and stores them in the File Store. Any settings that it needs are passed on via an Output Preset which is made with the Designer (see Output Creation Presets).

The nodes listed here are OL Connect nodes; see OL Connect nodes.

The OL Connect nodes are built are built in such a way that the output of a node is automatically recognized as input by the next node.

  • The data mapping node outputs a Data Set ID in msg.dataSetId which is used by the paginated content node to retrieve the data and create a set of content items.

  • The paginated content node outputs a Content Set ID in msg.contentSetId which is used by the paginated job node to create a print job.

  • The paginated job node outputs a Job Set ID to msg.jobSetId which is used by the paginated output node to generate output.

To build the flow you also need some nodes that are available by default or have been made by other parties. See Nodes used in OL Connect flows.

The all in one node is the fastest and most efficient way to create print output, as in that case multi-threading is supported: the data set and content items are produced in parallel.

The separate nodes would be of use in situations like the following:

  • The record set, created by the Execute Data Mapping task, is also needed to create another kind of output in the same flow.

  • The input is JSON data which can be used directly and doesn't need to be stored in the database. In this case there is no need to use the data mapping node or data get node.

  • The Print Content Items have already been created, either in the same flow or in another flow. Print Content Items can be retrieved from the OL Connect database using the data get node. Subsequently, the paginated job and paginated output nodes can generate print output from them.
    Note that at the time the Print Content Items are created, their Print Content Set ID needs to be stored somewhere where the print flow can access them, in order to retrieve the Print Content Items. You could for example use MongoDB.

  • If there is no need to merge the extracted data with an OL Connect template, the document mapping node can be used to create a Content Set as well as a Record Set, so that content creation - normally performed by the paginated content node - can be skipped. This requires paginated input data, for example a PDF or PS file, and a data mapping configuration.

Retrieving the output

The print output node outputs two things: the ID of the output location in the File Store and an array containing the output file(s). Connect the print output node with the OL Connect file download node to download a ZIP archive of the entire job based on the msg.managedFileId provided by the print output node. The data is read into a data buffer which allows it to then be written to disk using the write file node.

The target location can set by entering the full path in the Filename field of the file node. The other option is to set it dynamically in msg.filename, using a change or function node.

Downloading individual output files

The array that the print output node outputs can be used to download the files individually.
You will need a split node to iterate over the array in msg.payload and generate a new message for each file, setting msg.payload to the respective file name. See Iterating over items in an array.

Make sure to clear the Filename field in the write file output node before deploying the flow. A value configured in the node takes precedence over the msg property - msg.filename in this case - and will be used for every file, overwriting the previous file.

Files used in a print flow

Before creating a print flow, you will need to create:

In addition, the flow may use:

  • A data mapping configuration, if the documents should contain variable data that is extracted from some data source. (See Creating a new data mapping configuration.)

  • A Job Preset. (See Job Creation Presets Wizard.) A Job Preset defines where the output goes and makes it possible to filter and sort records, group documents, and add metadata.

  • An Output Preset. (See Output Presets.) An Output Preset can split a print job into smaller print jobs, and set printing options such as binding, OMR markings and the like.

All of these files are made with the Designer and need to be sent to the OL Connect server before using them in a flow; see OL Connect resources in Node-RED.