Skip to main content
Participant
July 6, 2016
Answered

Save As Extracted Pages with Javascript

  • July 6, 2016
  • 2 replies
  • 1336 views

I am working with Acrobat XI and currently using the built in javascript console and running the script with the action menu.  I have a large document ~550 pages.  It is a combination of 46 other reports.  I need to break these reports out and save them.  I am currently able to extract all of the reports using this.extractPages(0,13) and just setting the pages for each of the 46 reports.  The problem is that I still have to then save and close each of the files.  this.save() appears to only save the parent document. I am hoping that I can add to the script so that it saves the files to a location local or networked at a minimum.  Preferably I would be able to specify the name of each of the files individually as well.

I have tried this.extractPages(0,13,"\\server\folder\subfolder\filename.pdf"); with no luck.  If anyone has any suggestions I would appreciate it.

This topic has been closed for replies.
Correct answer try67

Your file-path parameter has an incorrect structure. You need to use the so-called "platform independent path".

The best way to find out how it needs to look is to open a file from that folder and then run this code from the console:

this.path;

It will output the file-path in the correct structure that you need to use in your script.

2 replies

Karl Heinz  Kremer
Community Expert
Community Expert
July 6, 2016

Take a look at the documentation for Doc.extractPages(): Acrobat DC SDK Documentation

It shows in the examples how the path needs to be specified as a device independent path (in your case, it would be  "/server/folder/subfolder/filename.pdf"). You can find out more about device independent paths in the PDF specification.

There is one other useful bit of information in the documentation: When you do not specify the output path, the method will actually return the document object for the newly created document: "If cPath is not specified, returns the Doc for the new document; otherwise, returns the null object."

With that document object, you can then further modify the document and save it via the Doc.saveAs() method (but again, the path needs to be specified as device independent path).

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
July 6, 2016

Your file-path parameter has an incorrect structure. You need to use the so-called "platform independent path".

The best way to find out how it needs to look is to open a file from that folder and then run this code from the console:

this.path;

It will output the file-path in the correct structure that you need to use in your script.

NCAD1Author
Participant
July 6, 2016

That took care of it.  Thank you!