Skip to main content
Known Participant
December 14, 2017
Answered

File location using event.target.buttonImportIcon

  • December 14, 2017
  • 1 reply
  • 1739 views

I would like to insert an image by pressing a button and have it automatically insert an image from my downloads folder.

Currently:

I have a button field and under action I have it run the following javascript event.target.buttonImportIcon();

With this javascript when i click the button it brings open another window where i have to browse for the image file before opening.

Is there a way to modify the javascript such that it will automatically open the image file by coding the address of the file?

I have tried event.target.buttonImportIcon(":C/Users/..../imagename.pdf") and that did not work.

Thanks

This topic has been closed for replies.
Correct answer Thom Parker

Here's an article about trusted functions.

https://acrobatusers.com/tutorials/trust-and-privilege-in-acrobat-scripts

Essentially you can only create trust inside a PDF with a digital certificate. Which is even more complicated and difficult that using a folder level function.

1 reply

Thom Parker
Community Expert
Community Expert
December 14, 2017

First, you need to get the path correct.

See this:

https://acrobatusers.com/tutorials/file-paths-acrobat-javascript

But ultimately, when used with the cPath parameter this function is privileged, so it can only be run from a trusted location.

Here's the SDK entry

Acrobat DC SDK Documentation

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
December 14, 2017

Thanks for your reply.

I changed the file location to:

event.target.buttonImportIcon("/C/Users/Downloads/90x90.pdf")

In regards to it being a privliged function I tried the following:

var cPath = "/C/Users/Downloads/90x90.pdf"

  trustedImport = app.trustedFunction( function (cPath)

   {

      app.beginPriv();    // Explicitly raise privilege

      event.target.buttonImportIcon(cPath);

      app.endPriv();

   })

In the degugger console it says

NotAllowedError: Security settings prevent access to this property or method.

App.trustedFunction:4:Field Button3:Mouse Up

I tried closing and reopening Adobe but still got the same error.

I also have Enable menu items JavaScript execution privileges

Thanks

try67
Community Expert
Community Expert
December 14, 2017

The trusted function needs to be located in a folder-level script.