Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
To be sure.
1. Are the marker stamps you've created available on the Stamp menu?
2. If so, when you place one on the PDF, does it look correct?
3. If so, the does it return the same AP that is in your code? i.e, does the stamp you placed manually return the same AP code?
And please post the actual stamp file as suggested by PDFAS.
BTW: the rect is very important. It doesn't have to be an actual rectangle. The right/left and top/bottom components can be the same, so that it is a point.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Can you share the stamp file?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Can you share the stamp file?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Yea, it returns the same AP.
Copy link to clipboard
Copied
To be sure.
1. Are the marker stamps you've created available on the Stamp menu?
2. If so, when you place one on the PDF, does it look correct?
3. If so, the does it return the same AP that is in your code? i.e, does the stamp you placed manually return the same AP code?
And please post the actual stamp file as suggested by PDFAS.
BTW: the rect is very important. It doesn't have to be an actual rectangle. The right/left and top/bottom components can be the same, so that it is a point.
Copy link to clipboard
Copied
Thanks, you guys helped me figure it out. I kept checking the AP for the stamps that were already in the file. Once I placed a new stamp in from the stamp menu, I checked this AP and it was different. I plugged in the new AP and it worked. Thank you guys, I really appreciate your help.
Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
You script should work if you change the AP property in your script to match the one in this stamp file:
#29GkKO4QBd-AibBYGELZ-B
Copy link to clipboard
Copied
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.