Skip to main content
December 23, 2025
Answered

importDataObject() will not attach file using a path until it is run without a path first (Windows)

  • December 23, 2025
  • 2 replies
  • 737 views

I have the following in a document-level javascript:

//Refresh JSON file attachment
function reload_equipment_list(attachment_name, full_path) {
    if (this.dataObjects != null) {
        //Delete the existing equipment list
        this.removeDataObject(attachment_name);
    }

    //Import the new equipment list
    this.importDataObject(attachment_name, full_path); //automatic form
    //this.importDataObject(attachment_name);            //manual form
}

 

On Windows, this line (which I'm calling the automatic form) fails:

this.importDataObject(attachment_name, full_path);

I don't get an error message in the console or anything, the function just refuses to import the file.

 

If I use this form, (which I'm calling the manual form):

this.importDataObject(attachment_name);

It allows me to choose the file I want. Once I run this form at least once, the automatic form will suddenly start to work. It's almost like the function doesn't have permission to access the file directory until the manual form is run.

 

If you re-open the document, the behavior resets. You have to run the manual form once for it to behave as expected. This is not the case on Mac. The automatic form works on startup without having to run the manual form.

 

I would like to know if this is a bug or if there is some setting in the Windows version I'm missing.

Correct answer PDF Automation Station

Thanks for the simpler path code! I made the changes you suggested but it's still behaving the same way. It will not work until the manual form of importDataObject is run first.


Under Edit>Preferences (Ctrl +k) > Security (enhanced), is "Enable protectect mode at startup" unchecked?  If not, uncheck it and restart Acrobat.

2 replies

Thom Parker
Community Expert
Community Expert
December 23, 2025

If you look at the reference, it states that this function requires privilege if the path is specified. 

Reference entry: https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#importdataobject

 

Here's an article that discusses privilege and the trusted function:

https://www.pdfscripting.com/public/Using-Trusted-Functions.cfm

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
December 23, 2025

I did come across that when I was first writing this code. I added the folder containing the PDF and the JSON to Privileged Locations. Is that not enough on Windows? Because it's working on Mac.

PDF Automation Station
Community Expert
Community Expert
December 24, 2025

You must rewrite the function as a trusted function in a text file, save it as a JavaScript file (.js file extension), place this file in the application JavaScripts folder, and remove the doc level script.

PDF Automation Station
Community Expert
Community Expert
December 23, 2025

Are you running the script from the console?

December 23, 2025

Not the console. I have it running from the document-level javascripts.

PDF Automation Station
Community Expert
Community Expert
December 24, 2025

I understand you have the function as document level script as you stated.  I was asking about the script that runs the function.  Is that from a button on the form?  If it is, then it shouldn't work according to the documentation because that is not a privileged context as @Thom Parker stated.