I have a PDF document with anywhere from 80 to 150 pages. We use Javascript in the admin console to extract each page and save the file based on some text at the top of each page. The code below works except for when the file has more than 49 pages. At first, I thought it was because the loop causes a race condition where closeDoc doesn't fire because the loop is still looping. But no matter what type of iterator I use, the script crashes on file 50 with the following error:
RaiseError: The maximum number of files are already open. No other files can be opened or printed until some are closed.
I even tried a 1-25 loop, then on to a 26 - 50 loop, etc. but the same error message always happens. I also tried app.setTimeout thinking that it would eliminate the race issue. I've also tried calling it as a function and passing in the page number. And unfortunately Acrobat DC does not include support for AWAIT.
Here is the code:
for(var i=0; i<this.numPages; i++) {
var oNewDoc = this.extractPages({nStart: i, nEnd: i});
//folderPath and filename logic goes here
oNewDoc.saveAs(folderPath+filename);
oNewDoc.closeDoc(true);
}
I need this to be a synchronous process. Anyone have any solutions?