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’

Hi @ChrisG,

Is there a way I can target a certain div box to print or not from within the control scripts for loop?

Please note that it is unfortunately not possible to select content from within a Control Script. The reason for this is because Control Scripts don’t have a selector and because the ‘query() - PReS Connect 2021.2 User Guide (link)’ function is unavailable from within a Control Script.

I assume that the easiest option will be to use a second run of OL Connect Workflow plugins to:

  1. (Data Mapping Configuration) Split the PDF input file into records based on the condition if a page contains the text “Enclosure 1” at a certain location.
  2. (Template) Use the PDF input file as background for a Print Context Section of your Template and add the specific div-element, which you would like to add to a page which contains the text “Enclosure 1”, to the Master Page or Print Context Section of your Template.

Thanks Marten, appreciate you have a look into it for me

1 Like