Copy link to clipboard
Copied
The following code works well on previous acrobat revision, but now on acrobat DC doesn't work. Please give some help tips, thanks!
doc = app.openDoc({ cPath: "/C/temp/doc1.pdf" })
// List of files of different extensions
aFiles = new Array( "doc2.jpg ", "doc3.jpg ", "doc4.pdf");
for ( var i=0; i < aFiles.length; i++) {
// Open and convert the document
newDoc = app.openDoc({
oDoc: doc,
cPath: aFiles,
bUseConv: true
})
// Save the new PDF file to a temp folder
newDoc.saveAs({ cPath: "/C/temp/tmpDoc.pdf" });
// Close it without notice
newDoc.closeDoc(true);
// Now insert that PDF file just saved to the end of the first document
doc.insertPages ({
nPage: doc.numPages-1,
cPath: "/C/temp/tmpDoc.pdf",
nStart: 0
});
}
RaiseError: This file is already open.
Doc.saveAs:12:Console undefined:Exec
===> This file is already open.
undefined
Copy link to clipboard
Copied
This happens because of a bug in Acrobat DC where the closeDoc method essentially doesn't do anything.
You should update the application to the latest version available, but I'm not sure it will solve it.
If it doesn't, you will need to work around it. For example, use a unique name for each temporary file, instead of the same one.
That way you won't have an issue with overwriting an open file, but you will only be able to process up to 50 files, as that's the maximum amount that Acrobat allows you to open at once.
Copy link to clipboard
Copied
Also: check whether openDoc returns NULL. Report this or ignore it, but don't try to continue with a nonexistent document object.