File location using event.target.buttonImportIcon

Community Beginner ,
Dec 14, 2017

Copy link to clipboard

Copied

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

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

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.

TOPICS
Acrobat SDK and JavaScript

Views

472

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

File location using event.target.buttonImportIcon

Community Beginner ,
Dec 14, 2017

Copy link to clipboard

Copied

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

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

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.

TOPICS
Acrobat SDK and JavaScript

Views

473

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Dec 14, 2017 0
Adobe Community Professional ,
Dec 14, 2017

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 14, 2017 0
Community Beginner ,
Dec 14, 2017

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 14, 2017 0
Most Valuable Participant ,
Dec 14, 2017

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 14, 2017 1
Adobe Community Professional ,
Dec 14, 2017

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 14, 2017 1
Community Beginner ,
Dec 14, 2017

Copy link to clipboard

Copied

Thanks that article solved my issue.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Dec 14, 2017 0