2022.2

Table Of Contents
Seealso:"BackgroundResource"onpage1294,"MediaPosition"onpage1296and"ControlScript:
SettingaPrintsection'sbackground"onpage845.
Cloning Print sections
ForbackgroundinformationoncloningPrintsections,see:"Dynamicallyaddingsections(cloning)"on
page846.
Cloningasectionbasedonthenumberofrecordsinadetailtable
Thisscriptcreatesasmanyclonesofasectionastherearerecordsinadetailtable.Itassignsthenew
sectionsauniquename.
var printSections = merge.template.contexts.PRINT.sections;
var numClones = record.tables['detail'].length;
for( var i = 0; i < numClones; i++){
var clone = printSections["Section 1"].clone();
clone.name = "my_section_clone_" + i;
printSections["Section 1"].addAfter(clone);
}
CloningasectionbasedondataandassignabackgroundPDF
Thisscriptclonesasectionbasedondatafields.Itdisablesthesourcesectionfirstandthencallsthe
addPolicy()function.addPolicy()clonesthesection,renamesitandsetsaPDFfromthe
resourcesasitsbackground.ItexplicitlyenablesthecloneandthenaddsittothePrintcontext.
var printSections = merge.template.contexts.PRINT.sections;
merge.template.contexts.PRINT.sections["Policy"].enabled = false;
if(record.fields.policy_a == 1) {
addPolicy('a');
}
if(record.fields.policy_b == 1) {
addPolicy('b');
}
function addPolicy(policy){
var resourceUrl = 'images/policy-' + policy + '.pdf';
var clone = printSections["Policy"].clone();
clone.name = "policy_" + policy;
clone.background.url = resourceUrl;
clone.enabled = true;
printSections["Policy"].addAfter(clone);
}
margins
ThemarginsobjectisusedtosetaPrintsectionorMasterPage'smarginsinaControlScript(see
"ControlScripts"onpage838and"ControlScriptAPI"onpage1271).
NotethatMasterPagesareonlyusedinaPrintcontext(see"MasterPages"onpage462).
Themarginsobjectisretrievedviathesectionobject(see"section"onpage1305)orviathemas-
terpagesarrayinatemplate(see"masterpage"onpage1274),respectively.
Page 1311