Skip to main content
Participating Frequently
April 1, 2020
Answered

Range Error: Invalid Argument value during Extracting pages

  • April 1, 2020
  • 6 replies
  • 3012 views

I am getting "RangeError: Invalid argument value" error when i run this script

this.extractPages(1, 6, "test.pdf");

but when i run script without file name as shown below,  it runs fine and creates a tmp pdf file.

this.extractPages(1, 6);

 

please can someone let me know steps to fix this issue so that i can create a file with name test.pdf

This topic has been closed for replies.
Correct answer try67

You said you were running it from the console... You can't use it from a doc-level script.

See the documentation of this method:

<Quote>

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.

</Quote>

6 replies

try67
Community Expert
Community Expert
April 1, 2020

It's a long shot, but can you share the file with us? Or just with me?

sk143Author
Participating Frequently
April 2, 2020

i am using sample pdf file from this link

 

https://acrobatusers.com/tutorials/extracting-pages-pdf-acrobat-javascript/

 

Direct link to PDF file: http://www.windjack.com/PDFSamples/NelsonsInc_Employee1040s.pdf

 

Steps I follow to execute the script

1) Save the file in my local drive

2) Open it with acrobat pro DC

3) Click tools - javascript

4) Click Document Javascripts

5) add a new script and enter this 

this.extractPages(5, 5, "TestExtract1.pdf");
6) Close the editor and click debugger - i get this error "RangeError: Invalid argument value."

 

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
April 2, 2020

You said you were running it from the console... You can't use it from a doc-level script.

See the documentation of this method:

<Quote>

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.

</Quote>

try67
Community Expert
Community Expert
April 1, 2020

I don't think so... Maybe check that Protected View is Off under Edit - Preferencs - Security (Enhanced).

Does it work if you specify the full file path, instead of just the file-name?

For example:

this.extractPages(1, 6, "/C/Temp/test.pdf");

sk143Author
Participating Frequently
April 1, 2020

Protected view is off, and tried with full path still same error 😞

try67
Community Expert
Community Expert
April 1, 2020

Strange. It's working fine for me. Is this the full code you're running, or is it part of something bigger?

sk143Author
Participating Frequently
April 1, 2020

this is the full code i am running, once this is successful i will be building some more logics on top of this. Do i have to make any changes to any settings in my acrobat pro DC.

try67
Community Expert
Community Expert
April 1, 2020

Also, where is the file saved?

sk143Author
Participating Frequently
April 1, 2020

Many thanks try67 for your swift responses.

 

main pdf file is on my desktop, i tried it from one of my local folders as well, still same error.

 

The pdf has over 600 pages.

try67
Community Expert
Community Expert
April 1, 2020

And how many pages are there in the file?

try67
Community Expert
Community Expert
April 1, 2020

From where are you running this code?

sk143Author
Participating Frequently
April 1, 2020

i am running this from document javascript console.