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

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

Community Beginner ,
Apr 15, 2016 Apr 15, 2016

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

TOPICS
Acrobat SDK and JavaScript , Windows

Views

11.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 , Apr 18, 2016 Apr 18, 2016

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

Votes

Translate

Translate
Community Expert ,
Apr 15, 2016 Apr 15, 2016

Copy link to clipboard

Copied

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 ,
Apr 15, 2016 Apr 15, 2016

Copy link to clipboard

Copied

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

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 ,
Apr 15, 2016 Apr 15, 2016

Copy link to clipboard

Copied

Info about the methods are available in the Javascript Reference:

Acrobat DC SDK Documentation

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 ,
Apr 15, 2016 Apr 15, 2016

Copy link to clipboard

Copied

The correct method for this is Doc.buttonImportIcon() - you can find the documentation here:

Acrobat DC SDK Documentation

If you already have the icon in your document, you could also use Doc.buttonSetIcon():

Acrobat DC SDK Documentation

Both links have some sample code.

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 ,
Apr 18, 2016 Apr 18, 2016

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?

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 ,
Apr 18, 2016 Apr 18, 2016

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.

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 ,
Apr 18, 2016 Apr 18, 2016

Copy link to clipboard

Copied

Thanks, I'll look into it.

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 ,
Apr 18, 2016 Apr 18, 2016

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:

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

?

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 ,
Apr 18, 2016 Apr 18, 2016

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.

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 20, 2021 Dec 20, 2021

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

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 20, 2021 Dec 20, 2021

Copy link to clipboard

Copied

No.

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 21, 2021 Dec 21, 2021

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");

 

Image filed1JPG.JPG

 

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 21, 2021 Dec 21, 2021

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.

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 ,
Apr 12, 2022 Apr 12, 2022

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

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 ,
Apr 12, 2022 Apr 12, 2022

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.

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
LEGEND ,
Apr 12, 2022 Apr 12, 2022

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.

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 ,
Apr 12, 2022 Apr 12, 2022

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

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 ,
Apr 18, 2016 Apr 18, 2016

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

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 ,
Apr 18, 2016 Apr 18, 2016

Copy link to clipboard

Copied

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

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 ,
Apr 18, 2016 Apr 18, 2016

Copy link to clipboard

Copied

What layout do you use in the properties of the button?

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 ,
Apr 18, 2016 Apr 18, 2016

Copy link to clipboard

Copied

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

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
New Here ,
Apr 21, 2017 Apr 21, 2017

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

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 ,
Apr 22, 2024 Apr 22, 2024

Copy link to clipboard

Copied

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

 

 

 

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 ,
Apr 22, 2024 Apr 22, 2024

Copy link to clipboard

Copied

I don't know.

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