Extract PDF Pages using Javascript in Acrobat – Batch Processing

Javascript not just rules the web. It has been considered as the primary language to power most of the scripting utilities. Adobe Acrobat provides full support to edit and manipulate the document using javascript code. Infact a lot of inbuilt native methods can be invoked using the javascript.

Creating Javascript Snippets :
1.GoTo Advanced -> Document Processing -> Batch Processing in Acrobat
2.Click New Sequence -> Write your Javascript
3.Select the Newly Created Sequence and Click Run Sequence

Here a snippet i got from a website which helps to split a pdf in to separate files with 3 pages in each pdf file


/* Extract pages to folder */
// Regular expression used to acquire the base name of file
var re = /\.pdf$/i;
// filename is the base name of the file Acrobat is working on
var filename = this.documentFileName.replace(re, "");
try {
    for (var i = 0; i < this.numPages; i = i + 3) {
        var j = i + 2;
        if (j >= this.numPages)
            j = i;
        this.extractPages({
            nStart: i,
            nEnd: j,
            cPath: "E:/output/" + filename + "_" + i + ".pdf"
        });
    }
} catch (e) {
    console.println("Aborted: " + e)
}

The above code is auto-explanatory. We are invoking the native extractPages of the current opened file with starting and ending arguments. And the cPath refers the output folder in which the file needs to be saved. This will be helpful if you want to process files in Bulk. The same feature can be accomplished from the menu Document->Extract Pages, if you are not interested in Bulk processing.

Happy coding in javascript.

AuthorNirmal

Technical Geek - Gadget Enthusiast - Loves Programming C#,PHP & IOS - Blogger About