Skip to main content
bryanmere88
Participant
June 19, 2016
Question

Extract pages JavaScript code is not working when I assign a file name to the extracted pages.

  • June 19, 2016
  • 1 reply
  • 1899 views

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.

This topic has been closed for replies.

1 reply

Inspiring
June 19, 2016

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

try67
Community Expert
Community Expert
June 19, 2016

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.

bryanmere88
Participant
June 20, 2016

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.