Skip to main content
Luxurynightmares
Known Participant
November 30, 2024
Answered

Placing custom stamp with JavaScript doesn't work

  • November 30, 2024
  • 3 replies
  • 1781 views

I have a PDF map with custom stamps.  The custom stamps are images of map markers, see the image below.  My goal is to create a button that places a new map marker (stamp) in the PDF. The problem is my code does not work for my custom stamp but it does for regular stamps.  The code does not load the custom image I used for the map marker.

The below image is what happens when I run the code.  It places the new stamp but without the image.

My code:

this.addAnnot({page: 0, type: "Stamp", AP: "#LA6uOA8puFBQLb6f_AoRaC"});

ODDLY ENOUGH... If I remove the AP from my code it works! (KINDA)  It will place the most recent stamp I imported into the document.  So if I goto Tools>Add a stamp>Stamp>Dynamic>MapMarker and place this stamp into the document... the button works perfectly.  But I want my button to place the stamp I choose, not what is recent.

I used this code to get the 'name' of my custom stamp:

this.selectedAnnots[0].AP

 Which returned this:

#LA6uOA8puFBQLb6f_AoRaC

 

If I change the AP name to one of the standard stamps, it works fine... which leads me to think something is off with the name and I can't figure it out.  Any insight into this will be super helpful as I've been going crazy trying to figure out why this isn't working.

This topic has been closed for replies.
Correct answer PDF Automation Station

My guess is that you don't have the stamp on your system.  That's why the other stamps work when you run the code with their APs.  This won't work if the stamp is not in your system.   Even if it is, every single user of the PDF would need the stamp file in order for this to work.  I have a solution that doesn't require users to have the stamp on their systems.

1)  Select one of the marker stamps and copy it by pressing Ctrl + c.

2)  Press Ctrl + v multiple times to make multiple copies of the stamp (I'll use 4 in this example).

3)  Rename the copies Marker1, Marker2, Marker3, and Marker4 by individually selecting them and running the following script in the console:  this.selectedAnnots[0].name="Marker1"; (repeat for Marker2 through 4).  NOTE:  The name property is not the same as stampName in the stamp code, which is the AP property.

4)  Hide all the stamps by selecting them and running the following script in the console:

this.selectedAnnots[0].hidden=true; (repeat for the other 3)

5)  Replace the script in your button with the following:

if(this.getAnnot(0,"Marker1").hidden==true)
{this.getAnnot(0,"Marker1").hidden=false}else
if(this.getAnnot(0,"Marker2").hidden==true)
{this.getAnnot(0,"Marker2").hidden=false}else
if(this.getAnnot(0,"Marker3").hidden==true)
{this.getAnnot(0,"Marker3").hidden=false}else
if(this.getAnnot(0,"Marker4").hidden==true)
{this.getAnnot(0,"Marker4").hidden=false}

If you need more than 4 repeat the process and modify the script according to the pattern.

3 replies

PDF Automation Station
Braniac
December 1, 2024

My guess is that you don't have the stamp on your system.  That's why the other stamps work when you run the code with their APs.  This won't work if the stamp is not in your system.   Even if it is, every single user of the PDF would need the stamp file in order for this to work.  I have a solution that doesn't require users to have the stamp on their systems.

1)  Select one of the marker stamps and copy it by pressing Ctrl + c.

2)  Press Ctrl + v multiple times to make multiple copies of the stamp (I'll use 4 in this example).

3)  Rename the copies Marker1, Marker2, Marker3, and Marker4 by individually selecting them and running the following script in the console:  this.selectedAnnots[0].name="Marker1"; (repeat for Marker2 through 4).  NOTE:  The name property is not the same as stampName in the stamp code, which is the AP property.

4)  Hide all the stamps by selecting them and running the following script in the console:

this.selectedAnnots[0].hidden=true; (repeat for the other 3)

5)  Replace the script in your button with the following:

if(this.getAnnot(0,"Marker1").hidden==true)
{this.getAnnot(0,"Marker1").hidden=false}else
if(this.getAnnot(0,"Marker2").hidden==true)
{this.getAnnot(0,"Marker2").hidden=false}else
if(this.getAnnot(0,"Marker3").hidden==true)
{this.getAnnot(0,"Marker3").hidden=false}else
if(this.getAnnot(0,"Marker4").hidden==true)
{this.getAnnot(0,"Marker4").hidden=false}

If you need more than 4 repeat the process and modify the script according to the pattern.

PDF Automation Station
Braniac
November 30, 2024

You need to have the actual stamp file in your stamp folder in order to use addAnnot, otherwise it will add an annotation with no errors but not the correct stamp, which it can't find.  Do you have the actual stamp file in your stamps folder, and is it available on your stamps menu?

Luxurynightmares
Known Participant
December 1, 2024

Attached is the stamp file, which has a different name for some reason... And there are no other stamps in my stamp folder besides this one.

Yes, the stamp is available on my stamp menu under Dynamic Stamps.

PDF Automation Station
Braniac
December 1, 2024

You script should work if you change the AP property in your script to match the one in this stamp file:

#29GkKO4QBd-AibBYGELZ-B

PDF Automation Station
Braniac
November 30, 2024

Can you share the stamp file?

Luxurynightmares
Known Participant
November 30, 2024

I've removed the rect from the code because even if I add it,  it doesn't work.  I'm not worried about the location and size of the stamp at this stage.  I just need to get the image to work.

Luxurynightmares
Known Participant
November 30, 2024

Thank you but I meant the actual stamp file.  When try to add it with a script and you get the X, did you try selecting it and running this.selectedAnnots[0].AP?  Does it return the same AP?


Yea, it returns the same AP.