Skip to main content
Participant
May 25, 2017
Answered

Extract Pages from Batch of PDF's... a "simple" JS Question?

  • May 25, 2017
  • 1 reply
  • 768 views

So I already have some code that I found in these forums that works. Just trying to make it a bit better if possible.

I just want to extract a certain number of pages (in my script below I am extracting the first three) from a batch of PDF's, and have them saved as "Extracted OriginalFileName.pdf". So far so good. So here is that code:

var oldDoc = this; 

var newDoc = oldDoc.extractPages(0,2); 

newDoc.saveAs(oldDoc.path.replace(oldDoc.documentFileName, "Extracted " + oldDoc.documentFileName));

What I would really like it to do is go through the entire batch without any user interaction. Right now the Javascript editor window pops up and you have to click "Ok" for each document in the batch.

I did some searching, trying to find other simple scripts that behaved the same way, or other extraction scripts that might give me a clue as to what I might need to fix this relatively small issue and I have come up empty.

If someone could point me in the right direction I would appreciate it.

This topic has been closed for replies.
Correct answer try67

Instead of using the saveAs method you can specify the file-path directly as the third parameter of the extractPages method.

Also, make sure that the "Prompt User" box under the "Execute JavaScript" command in your Action is NOT ticked.

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
May 25, 2017

Instead of using the saveAs method you can specify the file-path directly as the third parameter of the extractPages method.

Also, make sure that the "Prompt User" box under the "Execute JavaScript" command in your Action is NOT ticked.

Participant
May 25, 2017

Wow I feel dumb. I thought I had unchecked that "prompt user" box but I had not. Thank You.

Would using the file path method keep the files from opening as they are created?

try67
Community Expert
Community Expert
May 25, 2017

I think so, yes. If not you can always call the closeDoc method on newDoc...