Skip to main content
March 20, 2018
Question

extractPages

  • March 20, 2018
  • 1 reply
  • 885 views

Hello !

I'm so sorry, perhaps this is a really stupid question, because I could have found the answer. I'v read so many posts about, but I can't reach what I want.

I'm using Acrobat 9 Pro. I want to extract or insert pages with a button in my pdf by using javascript. I know, it's not possible with a trigger in document scripts.

So I made a js-file named "insert_page.js" and put it into Adobe's javascript folder (C:\Program Files (x86)\Adobe\Acrobat 9.0\Acrobat\Javascripts). The content of the script simply is:

function extract_page()

{

this.addField("Testbutton", "button", 0, [100,100, 150, 80]);

this.getField("Testbutton").fillColor=["RGB", 1, 0, 0];

this.extractPages(0, 0, "/c/Users/destinationfolder/newPage.pdf");

}

Writing this in the console: everything works fine !!! Calling from the Button, nothing happens. What ist wrong ? Please help me !!

remark: the field is only added for being sure, that the function ist really called by clicking the button. I don't really need it. Interesting is just the extractPages call.

This topic has been closed for replies.

1 reply

Karl Heinz  Kremer
Community Expert
Community Expert
March 20, 2018

Whenever something does not work, see if you are getting any error reports in the JavaScript console. In this case, you should see a problem related to permissions being reported. See the API documentation for Doc.extractPages(), and you will find this note:

Note:If the cPath parameter is specified, this method can only be executed during a batch and console event, or through an external call (for example, OLE). See Privileged versus non-privileged context for details. The event object contains a discussion of JavaScript events.

You need to create a "privileged context" to execute this function, which meant that you need to install a folder level script on every computer that needs to run this script.

March 20, 2018

I already read this all. But obviously I don't understand, ...

Now I have:

trustedNewDoc = app.trustedFunction(function ()

{

app.beginPriv();

app.extractPages(0, 0, "/c/Users/destinationfolder/newPage.pdf");

app.endPriv();

}

I try to execute by using mouse-up action of a button with:

trustedNewDoc();

Doesn't work.

Karl Heinz  Kremer
Community Expert
Community Expert
March 20, 2018

Where do you define your trusted function? Are you getting any error message on the console?