Dynamic stationery image
Virtual stationery refers to a digital version of pre-printed paper stock, like letterheads, intended for use in electronic documents or printed materials. In OL Connect, you can use virtual stationery by assigning a PDF as the background image for media.
The stationery image can either be static or dynamically set. Dynamic stationery is especially useful in scenarios where different brands need to be showcased depending on the value of a data fields.
In this tutorial, you will learn a technique to dynamically set virtual stationery. This is achieved by changing the background image for media based on data.
The tutorial demonstrates how to switch between different brands depending on specific data conditions. We will use pdf images added to the Images folder located in the Resources view of the template. The names of these images are prefixed with the name of the company (‘olacme-‘) and the second part matches the data provided in the brand
data field.

The goal is to show a brand-specific background image for the pages in our section.

Steps
Changing the background image dynamically requires a Control Script. Control Scripts determine how different sections of the context are handled. They can be used to omit Print sections from the output, clone Print sections and, in this particular case, set the background image of Media entries.
To create the Control Script:
- Choose Control Script from the New Script icon located in the toolbar of the Scripts pane.
- Enter a name for the script and delete the sample code.
- Add the code below. It stores the media entry and the value of the brand data field in the
media
andbrand
variables. This helps us to keep the code tidy.
let media = merge.template.media["Media 1"]
let brand = record.fields.brand
- Add the following code to the script. The first line enables the option to set an image for the front side of the media entry. The second line constructs the path (URL) to the image in the Resources using the value stored in our
brand
variable.
media.stationery.front.enabled = true
media.stationery.front.url = "images/olacme-" + brand + ".pdf"
Tip! The path could also be constructed using JavaScript Template literals, also known as Template strings. This provides a convenient and more expressive way to create strings by embedding expressions within backticks (`
), instead of combining strings surrounded by the traditional single or double quotes. For example:
media.stationery.front.url = `images/olacme-${brand}.pdf`
- Click OK to save the script and toggle to the Preview mode to view the script in action.