Skip to main content
Participating Frequently
January 19, 2024
Question

JavaScript importDataObject in trusted JS functrion still generatesNotAllowedError

  • January 19, 2024
  • 3 replies
  • 1433 views

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

This topic has been closed for replies.

3 replies

JR Boulay
Community Expert
Community Expert
January 22, 2024

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 Photoshopographe
Participating Frequently
January 22, 2024

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. 

JR Boulay
Community Expert
Community Expert
January 22, 2024

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 Photoshopographe
Thom Parker
Community Expert
Community Expert
January 20, 2024

And, 

What security options have you tried?

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
January 22, 2024

The application is Adobe Acrobat Reader (see details attached)

try67
Community Expert
Community Expert
January 19, 2024

- Where did you place this code?

- How are you calling it?

- Where are you calling it from (what application and version)?

Participating Frequently
January 22, 2024

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

 

try67
Community Expert
Community Expert
January 22, 2024

This will only work in Acrobat. Reader can't attach files like this, only as an annotation.