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

Javascript- Insert a specific image into the pdf

Community Beginner ,
May 06, 2021 May 06, 2021

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
9.3K
Translate
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
1 ACCEPTED SOLUTION
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.forReal && (event.source.stampName == "#ZPjduwxgTAoCc5syxiNeSA"))

{

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

  cMsg += "/2021 "

  event.value = cMsg;

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

}

View solution in original post

Translate
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

You can use a stamp for this.

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

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

Translate
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
I need to add a date and a client number.

But it needs to be different every time I insert the image.
Translate
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

You can use a dynamic stamp.

Translate
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

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

Translate
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

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

Translate
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

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?

 

Translate
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
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;

}
Translate
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
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

Translate
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