An OL Connect preview PDF flow in Node-RED

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

Tip: An example preview PDF flow is provided by OL Connect Automate, once installed. The example appears 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 preview PDF flow needs, is to use a Sample Project. There are two Sample Projects that create a sample print project; see Sample Projects. For a PDF preview flow in Node-RED you would use the template and possibly the data mapping configuration; you would not use the Workflow configuration file.

The structure of a preview PDF flow

Serving a preview to a browser

Typically, a PDF preview flow consists of at least three nodes: an http in node that receives the request, the preview pdf node which is one of the OL Connect nodes, and the http response node to serve the preview.

The http in and http response nodes are standard nodes. See Node-RED: nodes and common techniques.

The HTTP in node will pass any query parameters via the payload as JSON data. Query parameters are key/value pairs attached to the end of an URL. The first parameter is appended to the URL using a ? (question mark). If there are multiple parameters, an & (ampersand) is added in between them.
For example: http://localhost:1881/hello?first=John&last=Doe.

The preview pdf node accepts JSON data provided via the msg.payload property. Note that in order to merge the data with a template, the parameter names must match field names in the template's data model.

The template to use can be configured in the preview pdf node or passed via the msg.template property. (See: Setting and moving msg properties.)

The preview pdf node accepts runtime parameters. These can be passed via the parameters property of the msg object which is passed between nodes.
For example, a runtime parameter named brandId would be passed via msg.parameters.brandId.

Creating and saving multiple PDF files

A PDF preview is usually needed in online solutions, but the preview PDF node can also be used in situations where a PDF file can be produced without an Output Preset.

In such situations the flow could for example have an OL Connect data get node (see OL Connect nodes) that outputs an array of Data Record IDs, followed by a standard split node, OL Connect's preview pdf node and a standard write file node.

The preview pdf node can only take one data record ID at a time. That's why you will need the split node to iterate over the array in msg.payload and generate a new message for each file, setting msg.payload to the respective Data Record ID. (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 preview PDF flow

Before creating a preview PDF flow, you will need to create:

In addition, the flow may use:

These files are made with the Designer and need to be sent to the OL Connect server before using them in a flow. For instructions see OL Connect resources in Node-RED.