2021.2

Table Of Contents
Control Script: Setting a Print section's background
In the Print context, an image file can be used as a Print section's background; see "Using a
PDF file or other image as background" on page492.
If you want the section background to be switched automatically, depending on the value of a
data field, you need a Control Script. There is a Script Wizard that can generate that script for
you, provided that certain conditions are met; see: "Dynamic Print section backgrounds" on
page844.
Otherwise, you will have to write the Control Script yourself. This topic explains how to write a
Control Script that sets a Print section's background.
Note that the settings made in a Control Script take precedence over the settings made in the
Print Section Properties dialog.
Note
Encrypted PDF files are not supported in PDF pass-through mode.
For information about Control Scripts in general, see "Control Scripts" on page913 and
"Control Script API" on page1405. If you don't know how to write scripts, see "Writing your own
scripts" on page877.
Setting a background in script
The Control Script should first enable a background on the section, in case an initial
background wasn't set via the user interface. This is done by setting the source type for the
background of the section to either DataMapper PDF orResource PDF (see
"BackgroundResource" on page1438). For example:
merge.template.contexts.PRINT.sections['Policy'].background.source
= BackgroundResource.RESOURCE_PDF;
For a DataMapper PDF, nothing else has to be done to set the background.For a Resource
PDF, the Control Script should specify a path, for example:
var resourceUrl = 'images/policy-' + record.fields.policy + '.pdf';
merge.template.contexts.PRINT.sections['Policy'].background.url =
resourceUrl;
Page 922