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
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.
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
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
Copy link to clipboard
Copied
The trusted function needs to be located in a folder-level script.
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.
Copy link to clipboard
Copied
Thanks that article solved my issue.