Copy link to clipboard
Copied
Our company needs to split mulitple pdf files. The files must = 25 pages or less after spliting. For example 102 page file would output 5 files. 4=25pages, and 1=2 remaining pages. I have a script but it only outputs 2 pages.
/*Extract pages 25 at a time with leading zerors for proper sort */
function padLeft (s,len,c){
c=c || '0';
while (s.length< len) s= c+s;
return s;
}
// regular expression used to acquire the base name of file
var re = /\.pdf$/i;
//file name is the base name of the file acrobat is working on
var filename = this.documentFileName.replace (re,"");
try {for (var i = 0; (i*2) < this.numPages; i++)
this.extractPages({
nStart: i * 2,
nEnd: (i * 2) + 1,
cPath: filename + "-" + padLeft ((i + 1) + "",3) +".pdf"
});
} catch (e) { console.println("Aborted: " + e)}
This code should work better:
for (var i=0; i<this.numPages; i+=25) {
var startPage = i;
var endPage = i+24;
if (endPage>=this.numPages)
endPage = this.numPages-1;
this.extractPages({
nStart: startPage,
nEnd: endPage,
cPath: "..."
});
}
Copy link to clipboard
Copied
This code should work better:
for (var i=0; i<this.numPages; i+=25) {
var startPage = i;
var endPage = i+24;
if (endPage>=this.numPages)
endPage = this.numPages-1;
this.extractPages({
nStart: startPage,
nEnd: endPage,
cPath: "..."
});
}
Copy link to clipboard
Copied
Thank you- worked perfectly.
Copy link to clipboard
Copied
That's what it is written to do. Adjust the loop counters and the nStart and nEnd.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more