Opening same file twice in Javascript not working
Copy link to clipboard
Copied
I wish to open and close the same file while running a javascript, but in second attempt to open file, it does not open, the program stops running and no error message is generated. Opening and closing the same file works in Adobe Pro 9.3 but not Reader DC version 2020.009.20065. I am ruuning Windows 10, version 1909. This code works in previous versions of Reader.
Below is an example showing "SampleDoc.pdf" being opened and closed.
==========================================
var otherDoc = app.openDoc("SampleDoc.pdf", this);
//(program code not shown)
otherDoc.closeDoc(true);
//(program code not shown)
var otherDoc = app.openDoc("SampleDoc.pdf", this);
//(program code not shown)
otherDoc.closeDoc(true);
==========================================
Within Reader DC,
Javascript: Javascript: Enabled Acrobat JavaScript and JavaScript Debugger: Show console on errors and messages, are checked.
Security (Enhanced): Sandbox Protections: Enable Protected Mode at startup and Enhanced Security: Enable Enhanced Secuirty is not checked.
I have "this.disclosed = true;" at the document level.
In the Javacript folder within Reader DC and Adobe Pro 9.3, I added two JavaScript files:
0_SafeDataObjects, which contains the code:
myExportDataObject = app.trustPropagatorFunction(function(doc,name){
app.beginPriv();
doc.exportDataObject({cName: name});
app.endPriv();
})
myTrustedExportDataObject = app.trustedFunction(function(doc,name) {
app.beginPriv();
myExportDataObject(doc,name);
app.endPriv();
});
var myImportDataObject = app.trustedFunction(
function(doc,name,path){
app.beginPriv();
doc.importDataObject({cName: name, cDIPath: path});
app.endPriv();
})
var myGetPath = app.trustedFunction(
function(category, folder){
app.beginPriv();
return app.getPath(category, folder);
app.endPriv();
})
and, safeSave, which contains the code:
var safeSave = app.trustedFunction (
function(doc)
{
app.beginPriv();
doc.saveAs({cPath:doc.path});
app.endPriv();
}
);
Copy link to clipboard
Copied
There's a bug in Acrobat (and Reader) DC that prevents the closeDoc method from working, unfortunately.
Copy link to clipboard
Copied
Without rewritting over a 1,000 documents, is there a work around, that can be inserted in 0_SafeDataObjects or safeSave javascript files?
Copy link to clipboard
Copied
Not that I'm aware of.
Copy link to clipboard
Copied
Why want you open the same document twice?
Copy link to clipboard
Copied
I've coded more than 1,700 documents, some of which required the same file to be opened. The sample code I provided was a condencedversion of documents being linked together as required.

