Skip to content
Advertisement

Extract pages from PDF with javascript in Acrobat Pro

I am trying to create a script that will extract all pages from a pdf document and name them from the number of the pdf (say the pdfs name is 5047.pdf) and then increment the name for every page of the pdf so it produces 5048.pdf, 5049.pdf etc. However my script doesnt do anything.

var filename = 0;
for (var i = 0; i < this.numpages; i++)
this.extractpages

({
nStart: i,
cpath: filename + i + ".pdf"

});

Advertisement

Answer

Original link: https://forums.adobe.com/thread/969135

The solution, based on an answer from Adobe’s forum:

/* Extract Pages to Folder */

var re = /.*/|.pdf$/ig;

var filename = this.path.replace(re,"");
var lastPage=this.numPages-1;
{
    for ( var i = 0;  i < this.numPages; i++ ) 
    this.extractPages
     ({
        nStart: i,
        nEnd: lastPage,
        cPath : filename + "_page_" + (i+1) + ".pdf"
    });
};
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement