How to automate extracting pages from a PDF using AppleScript and Acrobat Pro?
Asked Answered
V

2

3

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?

Vance answered 4/9, 2013 at 18:17 Comment(0)
H
3

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:

enter image description here

Hurwitz answered 4/9, 2013 at 20:53 Comment(3)
This would definitely be a nice solution, but the reason I need to go through Acrobat Pro/Distiller is because this is for publishing, and I have to follow a specific .options configuration for Distiller. By extracting the pages this way, a new PDF is created by the OS X native Quartz framework.Vance
In that case I don't think I can provide a specific answer, as I don't have access to Acrobat Pro.Hurwitz
One possible way you could do this is with AppleScript UI scripting. You can use the Record feature of the Automator to record the UI interaction steps needed to do the Acrobat Extract Pages workflow. Then you can then literally select and copy the recorded steps in automator and paste them into a new Applescript Editor window. This will give you applescript which may or may not work. You'll probably want to edit the script, but at least it should help give an idea what is needed to do this programatically.Hurwitz
I
1

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 XI  - Edit Action

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]

Irv answered 28/5, 2015 at 17:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.