How to extract pdf pages with Javasript
Categories: Acrobat | Tags: Javasript, Pdf
Copy this script to the "Javascripts" directory under the Acrobat's applications directory. Restart Acrobat and now you have the "Extact to folder" menu under the Document menu. Before using you must create a folder "extracted" on drive C.
extractToFolder = app.trustedFunction(function()
{
var outFolder = "/C/extracted/";
var re = /\.pdf$/i;
var filename = this.documentFileName.replace( re, "" );
global.pageNum;
try {
for (var i = 0; i < this.numPages; i++ ) {
global.pageNum = i + 1;
if ( global.pageNum < 10 ) {
global.pageNum = "00" + global.pageNum;
}
else if ( global.pageNum < 100 ) {
global.pageNum = "0" + global.pageNum;
}
this.extractPages({nStart: i, cPath: outFolder + filename + "_" + global.pageNum + ".pdf"});
}
} catch (e)
{ app.alert("Aborted: " + e) }
}
)
// add the menu item
app.addMenuItem({
cName: "extractToFolderJS", // this is the internal name used for this menu item
cUser: "Extract to folder", // this is the label that is used to display the menu item
cParent: "Document", // this is the parent menu. The file menu would use "File"
cExec: "extractToFolder()", // this is the JavaScript code to execute when this menu item is selected
cEnable: "event.rc = (event.target != null);", // when should this menu item be active?
nPos: 0
});November 13, 2011 | Share:





