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.
The structure of a print flow
In its simplest form, a print flow may consist of only two nodes: one node that captures a data file, such as a watch, watch-directory or read file node, and the OL Connect all in one node.
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 Creation 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 Creation 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 OL Connect automation with Node-RED.
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.
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:
- A template with a Print context. (See Creating a template.)
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 Creation Preset. (See Job Creation Presets Wizard.) A Job Creation Preset defines where the output goes and makes it possible to filter and sort records, group documents, and add metadata.
- An Output Creation Preset. (See Output Creation Presets Wizard.) An Output Creation 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.