JavaScript importDataObject in trusted JS functrion still generatesNotAllowedError
Copy link to clipboard
Copied
Hi,
Don't know if someone already experienced the issue.
I used to add attachements to my pdf using the AddAnnot method in a trusted JS function, without issue.
For convenience, I moved to the importDataObject , giving more flexibilities. Unfortunately, and whatever security option i set in the reader, the following code generates the error:
NotAllowedError: Security settings prevent access to this property or method.
var import_doc = app.trustedFunction ( function (c,doc) {
app.beginPriv();
doc.importDataObject(c);
app.endPriv();
}
);
Any help or advise will be more than welcome.
Thanks
Phil
Copy link to clipboard
Copied
- Where did you place this code?
- How are you calling it?
- Where are you calling it from (what application and version)?
Copy link to clipboard
Copied
Hi,
The code is part of all my secured developped functions and the JS is stored in the expected location: C:\Program Files\Adobe\Acrobat DC\Acrobat\Javascripts. For info, all the other secured functions work fine.
one call exemple I call it from a "mouse up" event in a check-box, in the "run javascript" section. :
if(this.getField(event.target.name).value !== "Off") {
var c="CLO-"+event.target.name;
var doc="AccClosing"
console.println("Attaching file with name:"+c);
import_doc(c,this);
}
if(!checkAttached(c)){
app.alert("Atttaching a document is mandatory when this choice is selected");
this.getField(event.target.name).value="Off";
}
Error in the console:
NotAllowedError: Security settings prevent access to this property or method.
Doc.importDataObject:161:Field CB1-LCL:Mouse Up
Copy link to clipboard
Copied
This will only work in Acrobat. Reader can't attach files like this, only as an annotation.
Copy link to clipboard
Copied
Oh, I see. Not documented anywhere. I supposed all the JS code could be run on any adobe platforms and compatible. This is the first time I'm facing an incompatibility between products.
I used to use the annotations before, but found the importDataObject much more flexible. Thanks anyway for your time to answer.
Best.
Copy link to clipboard
Copied
It is documented in the JS API Reference, with the symbols under the method's name, but I agree it's not very clearly stated.
Copy link to clipboard
Copied
In the API doc i'm working with, the info is not so clear: Doc and Doc.Media APIs — Acrobat-PDFL SDK: JavaScript Reference (adobe.com)
please see abstract attached.
Copy link to clipboard
Copied
See the specification of the "D" value under Save-Prefs, here:
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/index.html#table-quick-key
Copy link to clipboard
Copied
I see indeed this was not obious! Thanks
Copy link to clipboard
Copied
And,
What security options have you tried?
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
The application is Adobe Acrobat Reader (see details attached)
Copy link to clipboard
Copied
This error message is misleading and the documentation is inaccurate.
You must go back to the addAnnot method because importDataObject is not supported by Acrobat Reader (Pro and Standard only).
Acrobate du PDF, InDesigner et Photoshoptographe
Copy link to clipboard
Copied
Thanks JR. My issue with the annots attachments is to be able to work with the attached file in a second phase. I need to open the attached file and get some info from it. Unfortunately I'm unable to find all the properties of the attachment object from a FileAttachment type annot. In addition, the documentation seems to say the attachment object type is a dataobject, but I cannot access it really as a dataobject. Do you have any clue how to achieve my goal?
thank you in advance.
Copy link to clipboard
Copied
What kind of property do you need to find?
Try this in the JS Console:
for (var i=0; i<this.dataObjects.length; i++)
{console.println("Attachment #"+i+": " +this.dataObjects[i].name);}
Acrobate du PDF, InDesigner et Photoshoptographe

