Using javascript to extract pages from PDF
Copy link to clipboard
Copied
Each month I get a large pdf file that I need to extract pages from and resave. The page numbers rarely change so this can had been working:
this.extractPages(0,1, "table1.pdf");
this.extractPages(2,15, "table2.pdf");
etc. for many more tables.
I recently "upgraded" to Adobe Acrobat Pro DC version 2021.005.20058
the code no longer works. I get an error message:
RaiseError: The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder. Doc.extractPages:1:Console undefined:Exec
There is no possible way for another user to have the file open - I just created it. I have searched on this error and seen many solutions, however none of them solve the problem.
Copy link to clipboard
Copied
Go to Edit (or the Acrobat app menu if you're on a Mac) - Preferences - Security (Enhanced) and disable Protected View Mode (or something similar).
Copy link to clipboard
Copied
That's not it. Using a PC, Protected View is already off.
Copy link to clipboard
Copied
How many pages are there in the file? What's the name of the original file? Where is the original file located (under what folder)?
Copy link to clipboard
Copied
Original file has 1084 pages, named "alltables.pdf".
all in folder c:\macros\adobe
Copy link to clipboard
Copied
Is there already a file with the name you're trying to save it under in that folder?
Copy link to clipboard
Copied
No, i don't have any other pdfs in that folder.
Copy link to clipboard
Copied
Are you able to manually extract those pages from the file?
From where are you running the code?
Copy link to clipboard
Copied
I can extract manually. I am running the code by opening "alltables.pdf", then go to tools > javascript and open the debugger. I paste the code from post #1 into the console, highlight the code, and execute by ctrl+enter. When I do this, I get the error message.
Copy link to clipboard
Copied
Protected View is NOT the option that matters. You need to turn off Protected MODE. The job of this option is to stop files from being written without a prompt, and so if you want to do that, the option will stop you...
Copy link to clipboard
Copied
Ah, I see. That option is checked, but also unable to be changed (grayed out). I think I'll have to check with my workplace's IT staff to try and chnage it. Thanks for your help.

