• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

File location using event.target.buttonImportIcon

Community Beginner ,
Dec 14, 2017 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

TOPICS
Acrobat SDK and JavaScript

Views

1.1K

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
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 14, 2017 Dec 14, 2017

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.

Votes

Translate

Translate
Community Expert ,
Dec 14, 2017 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

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Community Beginner ,
Dec 14, 2017 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

Votes

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
community guidelines
Community Expert ,
Dec 14, 2017 Dec 14, 2017

Copy link to clipboard

Copied

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

Votes

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
community guidelines
Community Expert ,
Dec 14, 2017 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.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
community guidelines
Community Beginner ,
Dec 14, 2017 Dec 14, 2017

Copy link to clipboard

Copied

LATEST

Thanks that article solved my issue.

Votes

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
community guidelines