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

Javascript- Insert a specific image into the pdf

Community Beginner ,
May 06, 2021 May 06, 2021

Copy link to clipboard

Copied

Hi,

Is there a way to use Javascript to insert an image into a PDF?

It would be something along the lines of:

Insert image from C:\Images\image.png...

and then the image would hover by the cursor to then be placed in the PDF.

I can use the image insert button, but I want to skip the step of choosing a file. 
I regularly insert the same file into PDFs and it would be quicker to go straight to that image.

 

Thanks.

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
TOPICS
JavaScript

Views

7.2K

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 Beginner , May 10, 2021 May 10, 2021
It’s usually in the same place but every now and then it needs to move to another place.

I was able to use a dynamic stamp with the following code to accomplish what I was trying to do.

The tricky part is getting the real name of the stamp. That’s on line 3 in the quotes starting with the #.

Shoutout to https://acrobatusers.com/tutorials/dynamic_stamp_secrets/ for help figuring this all out.

Check out their PDF sample.

var cAsk = "Enter the Date of the Wire" ;

var cTitle = "Wire Date ";

if(event.source...

Votes

Translate

Translate
Community Expert ,
May 06, 2021 May 06, 2021

Copy link to clipboard

Copied

You can use a stamp for this.

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 ,
May 06, 2021 May 06, 2021

Copy link to clipboard

Copied

Thanks.

I tried that before, but the problem with that is I need to type over the image I'm inserting.

You can't add text on top of a stamp. (If I'm incorrect on that, please let me 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 Expert ,
May 06, 2021 May 06, 2021

Copy link to clipboard

Copied

You can add text on top of a button image or a stamp, you just can't do it externally (unless flattened), it has to be done in that object (i.e. button or stamp). How much text do you need to place over the image?

 

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 ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

I need to add a date and a client number.

But it needs to be different every time I insert the image.

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 ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

You can use a dynamic stamp.

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 ,
May 07, 2021 May 07, 2021

Copy link to clipboard

Copied

You can read some about dynamic stamps here, watch the free videos. 

https://www.pdfscripting.com/public/All_About_PDF_Stamps.cfm

 

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 Expert ,
May 06, 2021 May 06, 2021

Copy link to clipboard

Copied

> and then the image would hover by the cursor to then be placed in the PDF.

This part is not possible, but the rest is. You can use a stamp, as mentioned, or a button field, or even insert it as a watermark. The latter will allow you to add text on top of it, but it's the more difficult one to place.

If you add it as a stamp or a button field you can then flatten the page and add text on top.

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 ,
May 08, 2021 May 08, 2021

Copy link to clipboard

Copied

Just curious, why are you considering only the use of stamps in this workflow?

 

Does the users of the form require to to have the freedom to place an image in whatever part of that document, or will this image be located always in a precise location?

 

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 ,
May 10, 2021 May 10, 2021

Copy link to clipboard

Copied

It’s usually in the same place but every now and then it needs to move to another place.

I was able to use a dynamic stamp with the following code to accomplish what I was trying to do.

The tricky part is getting the real name of the stamp. That’s on line 3 in the quotes starting with the #.

Shoutout to https://acrobatusers.com/tutorials/dynamic_stamp_secrets/ for help figuring this all out.

Check out their PDF sample.

var cAsk = "Enter the Date of the Wire" ;

var cTitle = "Wire Date ";

if(event.source.forReal && (event.source.stampName == "#ZPjduwxgTAoCc5syxiNeSA"))

{

  var cMsg = app.response(cAsk, cTitle);

  cMsg += "/2021 "

  event.value = cMsg;

  event.source.source.info.DocumentState = cMsg;

}

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 ,
May 17, 2021 May 17, 2021

Copy link to clipboard

Copied

LATEST

You'll find a video here which covers everything you'll ever want to know about the stamp name and several ways to find and change it.

 

BTW: the last line of your code won't work in Reader, and will cause the script to fail because the "info" property can't be changed on that platform. 

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