Split PDF Files based on size
I have a script that will split PDF files based on a set amount, so If I have a 1,000 page pdf, I have it split every 997 pages, I wish to modify it to split based on the actual size of the file.
So if the file is 1,000 pages read it and split it too 2 seperate 500 page documents or if it's a 1,200 page document split it into 5, 300 page documents, so my end goal is too split it evenly if the file is larger than 1,000 pages.
var re = /\.pdf$/i;
var filename = this.documentFileName.replace(re,"");
var n = 1;
var nParts = Math.ceil(this.numPages/998);
try {for (var i = 0; i < this.numPages; i+= 998){
var oNewDoc = this.extractPages({nStart: i,nEnd: (((i+997)>=this.numPages) ? this.numPages-1 : (i+997))});
oNewDoc.newPage({nPage: 0});
oNewDoc.addWatermarkFromText({cText: filename + "Part "+n + " of " + nParts,nStart: 0,nFontSize:36});
oNewDoc.saveAs({cPath: "/K/Penta/Split/"+filename+"_" +"Pages_" + (i+1) + "-" + (((i+998)>=this.numPages) ? this.numPages : (i+998)) +".pdf"});
n++;
oNewDoc.closeDoc(true);
}
} catch (e) { console.println("Aborted: " + e) }
