Skip to main content
Participant
November 27, 2018
Answered

Understanding how to use extractPages method correctly

  • November 27, 2018
  • 1 reply
  • 972 views

I have been searching all over the internet for full information on this, and I'm just having a very difficult time figuring it out and would appreciate any help I can get.

I have a function which is intended to automatically split PDFs based on the text of the page. According to the console, everything works fine in this function except for the "extractPages" function, which returns the following error:

RangeError: Invalid argument value.

Doc.extractPages:31:Document-Level:splitPages

As I looked into it, it appears that this function is a privileged function, and this is where I start getting confused. As far as I know, there is some folder-level script that needs to be added in a certain folder (which I believe I've found) which gives the program privileges to do this sort of thing. However, past that, I'm totally lost. Does the splitPages function itself go into that .js file in the folder level? How do I call it? How do I set the correct permissions?

If anyone can help me out, or direct me to a well-explained set of instructions, I would greatly appreciate it. Everything I've found so far talks generally about these things, but I can't find any specifics.

This topic has been closed for replies.
Correct answer gkaiseril

Adobe has determined that the ability of a script that can delete pages from a PDF should be reviewed by the user or the user's IT support to prevent some rouge code from removing pages from the user's PDF. It is well documented in the Acrobat JS Reference manual. You need to create a folder level script in either the application's level JavaScript folder or the user's Acrobat/Reader JavaScript folder.

Acrobat DC SDK Documentation Privileged vs Non-Privileged context

Acrobat DC SDK Documentation trustedFunction

1 reply

gkaiserilCorrect answer
Inspiring
November 27, 2018

Adobe has determined that the ability of a script that can delete pages from a PDF should be reviewed by the user or the user's IT support to prevent some rouge code from removing pages from the user's PDF. It is well documented in the Acrobat JS Reference manual. You need to create a folder level script in either the application's level JavaScript folder or the user's Acrobat/Reader JavaScript folder.

Acrobat DC SDK Documentation Privileged vs Non-Privileged context

Acrobat DC SDK Documentation trustedFunction

Participant
November 27, 2018

I had found the top and bottom links already, but the middle one was actually the one that helped me the most.

Specifically this part:

Place the following script in a .js file in the User (or App) JavaScript folder.

   trustedNewDoc = app.trustedFunction( function (nWidth, nHeight)

   {

      // Additional code may appear above

      app.beginPriv();    // Explicitly raise privilege

      app.newDoc( nWidth, nHeight );

      app.endPriv();

      // Additional code may appear below.

   })

After Acrobat is restarted, the trustedNewDoc function can be executed from anywhere. The following script for a mouse-up action of a button creates a new document that is 200 points by 200 points.

   trustedNewDoc( 200, 200 );

Thank you so much for the reference! It worked perfectly.

Legend
November 27, 2018

I strongly recommend you give your trusted function a name chosen by you and unguessable. The tendency to call all trusted function with obvious names undermines all the security and could lead to the whole thing being closed down as a weakness.