OL Learn

Dynamic backgrounds from pdf

Hi,
I have a PDF file (800 pages). These are 4-page documents. I need to make a dynamic background for each section.
I need it to work like this:
Section 1 : 1st page from pdf (1st record in database)
Section 2 : 2nd page from pdf (1st record in database)
Section 3 : 3rd page from pdf (1st record in database)
Section 4 : 4th page from pdf (1st record in database)

Section 1 : 5th page from pdf (2nd record in database)
Section 2 : 6th page from pdf (2nd record in database)
Section 3 : 7th page from pdf (2nd record in database)
Section 4 : 8th page from pdf (2nd record in database)

Section 1 : 9th page from pdf (3rd record in database)
Section 2 : 10th page from pdf (3rd record in database)
Section 3 : 11th page from pdf (3rd record in database)
Section 4 : 12th page from pdf (3rd record in database)

Thank you in advance for your help.

You can make use of a Control Script like the following for “Section 1 : 1st page from pdf (1st record in database)” for example:

Name: Example

var background = merge.template.contexts.PRINT.sections["Section 1"].background;

background.source = BackgroundResource.RESOURCE_IMAGE;
background.allPages = false;
background.start = 1; // Start page of the the PDF background
background.end = 1; // End page of the PDF background
background.url = "images/example.pdf";

In this example, I have assumed that the PDF file is added to the Images folder (shown in the Resources pane of the Connect Designer).

When this control script is applied, the first page is assigned to the first record.
Now I need this:

Section 1 : 1st page from pdf (1st record in database)
Section 2 : 2nd page from pdf (1st record in database)
Section 3 : 3rd page from pdf (1st record in database)
Section 4 : 4th page from pdf (1st record in database)

Section 1 : 5th page from pdf (2nd record in database)
Section 2 : 6th page from pdf (2nd record in database)
Section 3 : 7th page from pdf (2nd record in database)
Section 4 : 8th page from pdf (2nd record in database)

Section 1 : 9th page from pdf (3rd record in database)
Section 2 : 10th page from pdf (3rd record in database)
Section 3 : 11th page from pdf (3rd record in database)
Section 4 : 12th page from pdf (3rd record in database)
is it possible to do via script?

Before, I did this with a control script like this, but in this example i must split every pdf on pages 1, pages 2, pages 3, pages 4.

var section = merge.template.contexts.PRINT.sections[‘Section 1’];
var prefix = “images/Pages1.pdf”;
var filePath = record.fields.background;
var resourceURL = prefix + filePath;
section.background.source = BackgroundResource.RESOURCE_PDF;
section.background.url = resourceURL;
section.background.position = MediaPosition.FIT_TO_MEDIA;
section.background.allPages = false;
section.background.start = record.index;
section.background.end = record.index;
section.enabled = true;

Hi,

Something like this should assign the right pdf pages to the right sections.

var printSections = merge.template.contexts.PRINT.sections;
for( var i = 1; i < 5; i++) {
     printSections['Section '+i].background.start = (record.index-1)*4+i;
     printSections['Section '+i].background.end = (record.index-1)*4+i;
}

Best regards

Something’s not working.Can you show me where to put this script in the code?

Sorry. I posted just an idea for the control logic, which should be implemented into your control script…

If your sections are named “Section 1” through “Section 4”, your script should be something like this (not tested):

var printSections = merge.template.contexts.PRINT.sections;
var prefix = “images/Pages1.pdf”;
var filePath = record.fields.background;
var resourceURL = prefix + filePath;
for( var i = 1; i < 5; i++) {
printSections['Section '+i].background.source = BackgroundResource.RESOURCE_PDF;
printSections['Section '+i].background.url = resourceURL;
printSections['Section '+i].background.position = MediaPosition.FIT_TO_MEDIA;
printSections['Section '+i].background.allPages = false;
printSections['Section '+i].background.start = (record.index-1)*4+i;
printSections['Section '+i].background.end = (record.index-1)*4+i;
printSections['Section '+i]section.enabled = true;
}

You can also forget the upper code and just assign the start and stop for each section in the control script:

Section 1 --> background.start & background.end = (record.index-1)*4+1
Section 2 --> background.start & background.end = (record.index-1)*4+2
Section 3 --> background.start & background.end = (record.index-1)*4+3
Section 4 --> background.start & background.end = (record.index-1)*4+4
Example:
var section = merge.template.contexts.PRINT.sections[‘Section 1’];
(… other section stuff)
section.background.start = (record.index-1)*4+1;
section.background.end = (record.index-1)*4+1;

Hope it helps

Thanks. I changed last line and it works.