2022.2

Table Of Contents
ControlScript:SettingaPrintsection'sbackground
InthePrintcontext,animagefilecanbeusedasaPrintsection'sbackground;see"UsingaPDFfileor
otherimageasbackground"onpage451.
Ifyouwantthesectionbackgroundtobeswitchedautomatically,dependingonthevalueofadatafield,
youneedaControlScript.ThereisaScriptWizardthatcangeneratethatscriptforyou,providedthat
certainconditionsaremet;see:"DynamicPrintsectionbackgrounds"onpage759.
Otherwise,youwillhavetowritetheControlScriptyourself.ThistopicexplainshowtowriteaControl
ScriptthatsetsaPrintsection'sbackground.
NotethatthesettingsmadeinaControlScripttakeprecedenceoverthesettingsmadeinthePrintSec-
tionPropertiesdialog.
Note: EncryptedPDFfilesarenot supportedinPDF pass-throughmode.
ForinformationaboutControlScriptsingeneral,see"ControlScripts"onpage838and"ControlScript
API"onpage1271.Ifyoudon'tknowhowtowritescripts,see"Writingyourownscripts"onpage808.
Setting a background in script
TheControlScriptshouldfirstenableabackgroundonthesection,incaseaninitialbackgroundwasn't
setviatheuserinterface.Thisisdonebysettingthesourcetypeforthebackgroundofthesectionto
eitherDataMapperPDForResourcePDF(see"BackgroundResource"onpage1294).Forexample:
merge.template.contexts.PRINT.sections['Policy'].background.source = Back-
groundResource.RESOURCE_PDF;
ForaDataMapperPDF,nothingelsehastobedonetosetthebackground.ForaResourcePDF,the
ControlScriptshouldspecifyapath,forexample:
var resourceUrl = 'images/policy-' + record.fields.policy + '.pdf';
merge.template.contexts.PRINT.sections['Policy'].background.url = resourceUrl;
Note: Animagewithanunknownfileextensionisrepresentedbyaredcrossintheoutput,but
noerrorisloggedunlesstheimagereferstoalocalfilethatdoesnotexistondisk.
Imagefileextensionsthatthesoftwarerecognizesare:AFP,BMP,EPS,GIF,JPG/JPEG,PCL,
PDF,PNG,PS,SVG,andTIF/TIFF.
Positioning, scaling and rotating the background
Afterabackgroundhasbeenselected,itcanbepositioned,scaledandrotated,usingpropertiesofthe
backgroundobject;see"background"onpage1286.
Topositionthebackground,forexample,setthesection'sbackground.position:
Page 845