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

风格不统一 提交于 2020-01-01 16:53:51

问题


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?


回答1:


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:




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!