OL Learn

Get Total Records PDF input


Some time ago, you provided me with this script to get the total records from a csv-file throught the datamapper:

var reader = openTextReader(data.filename);
recordCount = 0;
while((line = reader.readLine())!= null){
recordCount = recordCount + 1;
recordCount = recordCount-1;
record.fields.TotalRecords = recordCount.toFixed(0);

Could you maybe help me to get the same result for a pdf-input?

DISCLAIMER: The following method can only work if each PDF page is a distinct record. If some records have more than a single page, it won’t work.

  • In the Pre-Processor step, create a Property named TotalPages with the following settings:
    • Scope: Entire data
    • Type: Integer
    • Default value: 0
  • In the Settings, set the Boundaries Trigger to On script
  • In the Expression field, add the following code:

Now in your data mapping process, you just have to extract the data.properties.TotalPages value to a field, it will contain the total number of pages in the PDF.

NOTE: the code above can be adapted to work if each record has a fixed number of pages (for instance, if all records have 2 pages). But as stated earlier, it cannot work if you have a variable number of pages per record. In that case, you’d be better off counting the pages through a script in Workflow and passing the value to the DataMapper.

Thank you yet again.

My pdf has 2 pages on every record.

i’m going to try it, thank you!

This code will work for 2-pagers. Note that I changed the name of the pre-processor property from TotalPages to TotalDocs.

var currPage = (boundaries.getVariable("CurrentPage") || 0);
if(currPage % 2 == 0){

Perfect thank you very much!