Skip to main content
Participating Frequently
April 15, 2016
Answered

Insert an image into pdf (Adobe Acrobat Pro DC) using javascript

  • April 15, 2016
  • 6 replies
  • 15291 views

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_imageis a variable I'm pulling from a database..

This topic has been closed for replies.
Correct answer try67

Did you actually set the button's Layout to "Icon Only"?

6 replies

Participant
April 21, 2017

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

Known Participant
April 22, 2024

Hi Bernd Alheit,

 

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

 

 

 
Bernd Alheit
Community Expert
Community Expert
April 22, 2024

I don't know.

Participating Frequently
April 18, 2016

Yeah I forgot to set it to Icon only.. that did it! Thank you

Participating Frequently
April 18, 2016

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.)...

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
April 18, 2016

Did you actually set the button's Layout to "Icon Only"?

Participating Frequently
April 18, 2016

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:

  • Tools -->
  • Action Wizard -->
  • New Action -->
  • More Tools -- >
  • Execute Javascript -- >
  • Specify Settings -->
  • *entering js code* + save action -->
  • running action from the Actions List

?

try67
Community Expert
Community Expert
April 18, 2016

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.

Known Participant
December 20, 2021

Hi there, is there a way not to click "Start" action instead of auto run the action when the form is opened?

 

Thanks,

Michael

Participating Frequently
April 18, 2016

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?

try67
Community Expert
Community Expert
April 18, 2016

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.

Participating Frequently
April 18, 2016

Thanks, I'll look into it.

Bernd Alheit
Community Expert
Community Expert
April 15, 2016
Participating Frequently
April 15, 2016

Do you have a link to any other source too? Not much info here...

Bernd Alheit
Community Expert
Community Expert
April 15, 2016

Info about the methods are available in the Javascript Reference:

Acrobat DC SDK Documentation