Copy link to clipboard
Copied
So basically, this what I want to do:
.this.getField('imageField').importImage('path_to_img');
I know this code is not correct, but is there a way to do this? I couldn't find the solution in Acrobat's documentation.
Most questions I found were referring to the problem when user is selecting an image on click of a button. I don't want that.
I need something like what I wrote above becausepath_to_image
is a variable I'm pulling from a database..
Did you actually set the button's Layout to "Icon Only"?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Do you have a link to any other source too? Not much info here...
Copy link to clipboard
Copied
Info about the methods are available in the Javascript Reference:
Copy link to clipboard
Copied
The correct method for this is Doc.buttonImportIcon() - you can find the documentation here:
If you already have the icon in your document, you could also use Doc.buttonSetIcon():
Both links have some sample code.
Copy link to clipboard
Copied
Thank you for the links provided, but I still have some troubles with making this work.
This is the code I wrote:
var f = this.getField("btnImage"); // button field
f.buttonSetCaption("Title");
if (f.buttonImportIcon("/C/image.pdf") == 0) // if 0 == no error
f.buttonImportIcon("/C/image.pdf");
I get the word "Title" written over the button field, but no image is displayed. I wrote the javascript in Action Wizard tool, under Custom Commands. I get no errors in Debugger.
Do I have to use buttonSetIcon() first? Or define the path to an image elsewhere?
Copy link to clipboard
Copied
From the documentation of buttonImportIcon:
Note: (Acrobat 8.0) If cPath is specified, this method can only be executed during batch and console
events. See Privileged versus non-privileged context for details. The event object contains a
discussion of JavaScript events.
Copy link to clipboard
Copied
Thanks, I'll look into it.
Copy link to clipboard
Copied
I apologize if this is a dumb question, but I just started using acrobat few days ago..
Is this sentence: "...this method can only be executed during batch and console..." equivalent to doing this:
?
Copy link to clipboard
Copied
It's not a dumb question at all, actually. And yes, I believe it should work from the context of an Action (as it is considered privileged), but try it out and let us know.
Copy link to clipboard
Copied
Hi there, is there a way not to click "Start" action instead of auto run the action when the form is opened?
Thanks,
Michael
Copy link to clipboard
Copied
No.
Copy link to clipboard
Copied
thanks. How about using the script to add the image by image action instead of action wizard. I tried the script here but not working. Any idea?
var f = this.getField("btnImage");
// Image field
if (f.buttonImportIcon("/C/image.gif") == 0)
// if 0 == no error
f.buttonImportIcon("/C/image.gif");
Thanks.
Copy link to clipboard
Copied
That requires a privileged context, as mentioned above. If you don't run it from an Action the main alternative is to run it from a trusted function in a folder-level script, which will have to be installed on the local machine of each user.
Copy link to clipboard
Copied
Hi Try67,
I got this working by putting the javascript in a folder-level via the document level or button level javascripts to trigger it to load the image in the system. But the new issue is I have to save the pdf first then reopen it in Adobe Reader DC to see the image but not to see the image in the pdf file opening in the Adobe Reader extension on an internet browser like IE/Edge/Chrome.
Do you know why?
Thanks,
Michael
Copy link to clipboard
Copied
Even I click the image button which has a javascript to trigger the folder-level javascript before I save the pdf file.
Copy link to clipboard
Copied
"I have to save the pdf first then reopen it in Adobe Reader DC to see the image but not to see the image in the pdf file opening in the Adobe Reader extension on an internet browser like IE/Edge/Chrome."
Sure, each of these uses its own PDF viewer, which may not allow JavaScript, or have a partial implementation; it certainly would have security limitations and won't read Adobe's startup files. This seems certain of failure in a browser.
Copy link to clipboard
Copied
Thanks for the reply.
Yes, after click "Fill & Sign" tool on Chrome/Edge browser, the image appears. IE does not need this step. Maybe that is only result we can have as IE is retiring.
Thanks:)
Copy link to clipboard
Copied
I did try it. I tried creating a new action, then I created a new custom command and after that I also tried doing it through tab Javascript --> Document Javascripts. And I just can't get the picture to show (everything else in the script works - pulling data from the excel file, changing colors of the fields, etc.)...
Copy link to clipboard
Copied
Did you actually set the button's Layout to "Icon Only"?
Copy link to clipboard
Copied
What layout do you use in the properties of the button?
Copy link to clipboard
Copied
Yeah I forgot to set it to Icon only.. that did it! Thank you
Copy link to clipboard
Copied
Hi Mirta,
Please can you explain to me how you achieved the final result.
I have it so that I can browse for an image through the button import but I want to be able to open a PDF and it automatically populate a field with an image of a specific name.
I think what you have done here would work but I'm not exactly sure where to place your code to test it.
If you or someone else can explain it to me I would be very grateful.
Cheers
Ross
Copy link to clipboard
Copied
Recently Try67 found a possible Reader DC bug to show the icon image from a folder level javascript. Do you know how long it will take to be fixed by Adobe?
Thanks,
Michael
Copy link to clipboard
Copied
I don't know.