2022.2

Table Of Contents
merge.context.sections['Section 6'].enabled = true;
merge.context.sections['Section 6'].part = "PDFAttach2";
}
}
Note: Foranotherexample,seethishow-to:Outputsectionsconditionally.
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130.
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"onpage325.
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"onpage398and"ControlScript
API"onpage815.Ifyoudon'tknowhowtowritescripts,see"Writingyourownscripts"onpage368.
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
ResourcePDF(see"BackgroundResource"onpage836).Forexample:
merge.template.contexts.PRINT.sections['Policy'].background.source = Back-
groundResource.RESOURCE_PDF;
ADataMapperPDFis,asyouwouldexpect,aPDFgeneratedbytheDataMapper.AResourcePDFis
aPDFfromanothersource.
ForaResourcePDF,theControlScriptshouldspecifyapath,forexample:
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.
Page 404