Enable PDF background on print section

I need some assistance with a control script to enable a PDF background resource to print along with a print section based on a record field:

record.fields[‘LetterTemplate’]

If LetterTemplate = Letter 1 the background to be included should be image1.pdf

If LetterTemplate = Letter 2 the background to be included should be image2.pdf

If LetterTemplate = Letter 3 the background to be included should be image3.pdf

Thanks

You may try something like this:

You will need to adjust the paths to your images. If the images are in the Images folder in Connect, simply use a relative path: ‘images/’ + backgroundImage

Reference:PlanetPress Connect 1.8 User Guide

var background = merge.template.contexts.PRINT.sections['Section 1'].background;
background.source = BackgroundResource.RESOURCE_PDF;

var backgroundImage ='';
var LetterTemplate = record.fields.LetterTemplate;

switch(LetterTemplate){
    case 'Letter 1':
        backgroundImage = 'image1.pdf';
        break;
    case 'Letter 2':
        backgroundImage = 'image2.pdf';
        break;
    case 'Letter 3':
        backgroundImage = 'image3.pdf';
        break;
    default:
        backgroundImage = 'image0.pdf';
}
var resourceUrl = 'file:///C:/Projects/SampleProject/Images/' + backgroundImage;
resourceUrl= resourceUrl.replace(/\s/g, "%20");
background.url = resourceUrl;