OL Learn

Conditional Text Based on Page Number

Hi All, I’m extracting the name and address from a PDF that contains multiple records - number of pages is variable per record. I’m then mail sorting the data and using this data in a Data Mapper. in the designer I’m using a control script to pull through the pages in the new sorted order

var pdfName,pageNum, totalPages, startNum, result = “images/”;

pdfName = record.fields[“PDF_NAME”];
pageNum = record.fields[“PAGE_NUMBER”];
totalPages = record.fields[“TOTAL_PAGES”];
startNum = record.fields[“STARTNUM”];

if (pdfName !== “”) {
result += pdfName;
}
else
{
logger.warn(‘NO PDF NAME’);
}

var background = merge.template.contexts.PRINT.sections[“FirstPage”].background;
background.allPages = false;
background.start = startNum;
background.end = startNum;
background.source = BackgroundResource.RESOURCE_PDF;
background.url = result;
background.position = MediaPosition.ABSOLUTE;
background.left = “0mm”;
background.top = “0mm”;

if(totalPages > 1)
{
for (let i = 2; i < totalPages; i++) {
startNum++;
var clone1 = merge.context.sections[“ContinuationPage”].clone();
var background = clone1.background;
background.allPages = false;
background.start = startNum;
background.end = startNum;
background.source = BackgroundResource.RESOURCE_PDF;
background.url = result;
background.position = MediaPosition.ABSOLUTE;
background.left = “0mm”;
background.top = “0mm”;

merge.context.sections[“FirstPage”].addAfter(clone1);
}
}

All works fine from what I can tell. I also need to add some of the text I have extracted to one of the following pages. Is there a way I can target a certain div box to print or not from within the
control scripts for loop?

Hi @ChrisG,

Can you let us know please what the condition is or conditions are whether a certain div-element should be shown/printed or not?

I am asking this because as far as I know is that you can’t target a specific HTML element from within a Control Script. So you will probably have to find out a way to do this by a Standard Script, by which we can help you of course.

Hi Marten, apologies for the delay in response.

As the page I want to print the field on is dynamic, I’m finding it within the data mapper using

var returnPage,InvoiceLocation;

for (let i = 0; i < steps.totalPages; i++) {
InvoiceLocation = data.find(‘Enclosure 1’,0,210);
if(InvoiceLocation != null)
{
returnPage = steps.currentPage;
}
steps.moveTo(1, i+1);
}

returnPage;

I want to then print on the page if its the particular page that contains - in this case ‘Enclosure 1’