Copy link to clipboard
Copied
I have a pretty simple code going here:
this.extractPages(35,37,"DISCLOSURES (PART 2) - BLANK AVID.pdf");
this.deletePages(35,37);
It's meant to extract a few pages from a document, automatically save them to the current working folder with the designated name, and then delete those pages from the original file. I've assigned this code to a button in the document. I swear, one minute it was working, and then it stopped. I've been at this for 8 hours straight so I may just be missing something so obvious but my tired eyes can't figure it out...I have other javascript buttons that involve changing fields to read-only and those are still working fine....any ideas anyone?
I've tried changing the file name. When I remove the name, the code works fine:
this.extractPages(35,37);
this.deletePages(35,37);
I'm using Acrobat Pro DC Version 2015.016.20045 on Windows 10 64bit.
Copy link to clipboard
Copied
The doc.extractPages method should not have ever worked when using in a button action. As described in the documentation, it is restricted from working unless called from a privileged context, such as in a folder-level JavaScript, the JavaScript console, a certified document that's been trusted to allow privileged JavaScript execution, etc. So if it has to work from a button in the PDF, either place the code in a trusted function and call the function, or certify the document if you don't want to install a folder JavaScript for some reason. More info: https://acrobatusers.com/tutorials/using_trusted_functions
Copy link to clipboard
Copied
That's not entirely true. The extractPages method can be used from a non-trusted context, but then you can't specify the file path (as the OP is trying to do). When used in this way it will generate a new Document object with the extracted pages and even return it, so it can be manipulated further.
Copy link to clipboard
Copied
Hmmm...okay. That explains why I can't name it. It's still interesting that naming it did work for a few attempts though, I'm sure of that. Anyway, it's not a must that it autosave when extracted so I'll probably just stick to simply extracting it as a temp file and saving it separately.
Copy link to clipboard
Copied
The saveAs function also requires a trusted context, though...
Copy link to clipboard
Copied
Right, I meant for the user to use File>Save As on the temporary file that is generated with those extracted pages. That seems to be working fine for me...although it is creating a temporary file...Do you happen to know where that temp file is?
Copy link to clipboard
Copied
The location of the temp folder will change per OS and Acrobat version. You can find out what it is by executing this code from the JS console: app.getPath("user", "temp");
Find more inspiration, events, and resources on the new Adobe Community
Explore Now