• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

Understanding how to use extractPages method correctly

New Here ,
Nov 26, 2018 Nov 26, 2018

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript

Views

282

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Nov 26, 2018 Nov 26, 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

...

Likes

Translate

Translate
LEGEND ,
Nov 26, 2018 Nov 26, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 26, 2018 Nov 26, 2018

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 27, 2018 Nov 27, 2018

Copy link to clipboard

Copied

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. 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 27, 2018 Nov 27, 2018

Copy link to clipboard

Copied

LATEST

Can you elaborate on that? Isn’t the name of the function called in the PDF document anyway? Couldn’t anyone access the name of it that way? And is this as much of a risk if I am just using it on my personal computer?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines