Split pdf on specific page number ranges

For example
1 - 4 would be a separate document
5 - 9 would be a separate document
10 - 12 would be a separate document
13 - 22 would be a separate document, etc

Each time files are processed the ranges could be different and would be read from a secondary data file. The files would be received as a match set 1234567890.pdf and 1234567890.xml. The pdf files are very large with around 1000 documents of various sizes within each pdf.

Not sure how to approach this using PPC 2019.1

My guess would be to use the alambic api?

var myPDF = Watch.GetPDFEditObject();
myPDF.Open(Watch.GetJobFileName(),false);
myPDF.Pages().ExtractTo('C:\\Tests\\Pages1-4.pdf',0,4,true);
myPDF.Pages().ExtractTo('C:\\Tests\\Pages5-9.pdf',4,5,true);
myPDF.Pages().ExtractTo('C:\\Tests\\Pages10-12.pdf',9,3,true);
myPDF.Pages().ExtractTo('C:\\Tests\\Pages13-22.pdf',12,10,true);
myPDF.Close();

Would need to extract within a loop so something like this?

var startonpage = [0, 4, 9];
var numofpages = [4, 5, 10];
var pdfname = ['1-4Pagers.pdf', '5-9Pagers.pdf', '10-19Pagers.pdf'];
var doccount = 3;
var i = 0;
var myPDF = Watch.GetPDFEditObject();
myPDF.Open(Watch.GetJobFileName(),false);

do {
  myPDF.Pages().ExtractTo('C:\\Tests\\' + pdfname[i],startonpage[i],numofpages[i],true);
  i++;
}
while (i < doccount);

myPDF.Close();

It seem you can do this with Metadata group.
You can assign document to a group then you split your PDF by group with Medata splitter.

HH

Your script would work. However, you don’t need 3 separate arrays to do this. A single array that just stores the length of each document provides you with all the info you need. For instance, the following code should achieve the same result and is easier to maintain:

var myPDF = Watch.GetPDFEditObject();
myPDF.Open(Watch.GetJobFileName(),false);

var docs = [4,5,10];
var start=0;

for(var i=0;i<docs.length;i++){
  var pdfName = (start+1) + "-" + (start+docs[i]) + "Pagers.pdf";
  myPDF.Pages().ExtractTo('C:\\Tests\\Output\\' + pdfName,start,docs[i],true);
  start += docs[i];
}

myPDF.Close();

Output: 1-4Pagers.pdf, 5-9Pagers.pdf, 10-19Pagers.pdf