Concatenate value from each page of a PDF

Have a PDF document with multiple pages. The PDF document is printed to workflow, but not all of the original PDF document will be printed, just sections. There are page numbers on each PDF page.

Need to extract the page number from each page and concatenate into a field. Then change the format to a range or ranges of pages. (i.e., 2-5, 9-12)

Section 1 is a background PDF from the data mapper. Section 2 is a trailing page with the additional information scraped from the page listed as human readable along with a barcode.

  • System Time Stamp (Now)
  • Actual Page Count (steps.TotalPages)
  • Page Range(s) from original document (extracted from each page of document)
  • Document Name (extracted from first page of document)
  • And a few more (extracted from first page of document)

Datamapper Boundaries
Only one document per PDF.
image

Not sure how to collect the Page Range(s).

I have this partially working, but can’t seem to get rid of an “undefined”.

I’m extracting the page numbers from each page and placing into detail table.
Then have an action to loop through the detail table and set the values in a “GlobalRange” Field.

I can replace the "undefined, ", but not sure why I’m getting the “undefined”.

For not I’m simply listing the page numbers, but eventually they want a real range of numbers.
In this example this would be “1-12”, but could be multiple ranges, such as “1-3, 5-7, 9, 11-12” if the page numbers were “1, 2, 3, 5, 6, 7, 9, 11, 12”.

var sRange, tmpStr, tmpStr2;
var arrayLength = record.tables.detail.length++;

for(var i = 0; i < arrayLength; i++) {
	tmpStr = record.tables.detail[i].fields.Range.trim();
	if(sRange == ""){
	    sRange = tmpStr;
	} else {
	    sRange = sRange+", "+tmpStr;
	}
}

sRange = sRange.replace("undefined, ", "")
record.fields.GlobalRange = sRange;

Try this instead:

var ranges=[];
for(var i = 0; i < record.tables.detail.length; i++) {
	ranges.push(" "+record.tables.detail[i].fields.Range.trim());
}
record.set({GlobalRange : ranges.toString().trim()});