I'm new to AppleScript, but I am trying to create a script that will go through all PDFs in a folder extracting the pages into separate files. My plan is to use a combination of Automator and AppleScript.
My AppleScript so far is:
tell application "Adobe Acrobat Pro"
open theFile
set numPages to (count active doc each page)
--execute the extraction here
end tell
The command in Acrobat Pro is under Options > Extract Pages...
, where I can specify the page range and to extract to separate files. However, I can't seem to find a way to do this with the Acrobat Pro Dictionary in AppleScript.
There is an execute
command that executes a menu item, but I can't seem to get it working (I'm also not sure of the syntax to use; i.e. execute "Options:Extract Pages..."
?). Any help on this?
I think you can do this entirely with the Automator without the need for AppleScript or Adobe software. The "PDF to Images" action splits a multi-page .PDF file into individual .PDF files, one per page:
You can use Adobe Acrobat Pro. Here is an example using Adobe Acrobat Pro XI. It uses Acrobat's "Actions" (previously called "Batch Processing") with custom JavaScript.
Adobe Acrobat Pro - Edit Action
You can create a new action that prompts the user to select a folder of pdf files to process. Then you can add JavaScript execution that searches for the pdf file names and extractPages function to extract all the pages from a PDF
Adobe Acrobat Pro - JavaScript
The following will extract all of the pages into separate PDFs. It appends a suffix on the end with each sheet number. It pads the sheet number with zeros based on the method described in the links which basically adds a bunch of zeros in front and then only slices out to take however many last digits of the string depending on how many sheets you typically have.
/* Extract Pages to Folder */
var re = /.*\/|\.pdf$/ig;
var filename = this.path.replace(re,"");
{
for ( var i = 0; i < this.numPages; i++ )
this.extractPages
({
nStart: i,
nEnd: i,
cPath : filename + "_s" + ("000000" + (i+1)).slice (-3) + ".pdf"
});
};
References
JavaScript for Acrobat API Reference > JavaScript API > Doc > Doc methods > extractPages
Extract pages to separate pdf's (something wrong with loop?)
How can I create a Zerofilled value using JavaScript?
How to output integers with leading zeros in JavaScript [duplicate]
来源:https://stackoverflow.com/questions/18621047/how-to-automate-extracting-pages-from-a-pdf-using-applescript-and-acrobat-pro