Skip to main content
Participant
Oct 15, 2020 10:51 AM UTC
Question

Place static stamp with javascript

We are placing static stamps on several pdf files and I would like to automate this. I am looking into javascript and trying to figure out how to set up a code. I would like a code to take a stamp named "Draft" and place it 50 mm from bottom and 50 mm from right.

 

I have tried to use add watermark and use the stamp as source file (and apply to multiple files) but it is not as easy to move the watermark, if necessary (for example if it is placed over something else). If the source file is added as a stamp and then the stamp is placed on the drawing it is much easier to just grab and move the stamp around.

This topic is closed to new replies. Start a new post to keep the conversation going.

6 replies

try67
Community Expert
Community Expert
Oct 15, 2020 3:43 PM UTC

A Stamp is an annotation (AKA "comment") so you can add it using the addAnnot method.

In order to do that you need to know a couple of things:

- The internal AP value of the stamp (its "name")

- The exact coordinates where you want to place it.

The best way to get both things is to manually apply it, and then select it with the mouse and execute the following code from the JS Console:

 

console.println(this.selectedAnnots[0].AP);

console.println(this.selectedAnnots[0].rect);

 

The output will be something like this:

 

SBDraft
18.898635864257812,228.94615173339844,132.0421905517578,278.6942138671875

 

You can use that to write your code. For example, this will add this stamp at that location to the first page of the file:

 

this.addAnnot({page: 0, type: "Stamp", AP: "SBDraft", rect: [18.898635864257812,228.94615173339844,132.0421905517578,278.6942138671875]});

 

You can use this code in an Action to process multiple files in a batch process.

Translate
Peter5C40Author
Participant
Oct 15, 2020 7:48 PM UTC

Thanks. I have got it to work now for most drawings but on some drawings no stamp is added. If I add a stamp manually and check the coordinates of the stamp, output is as below:

 

this.selectedAnnots[0].rect
161.57928466796875,-2108.416259765625,229.79925537109375,-1872.316162109375

 

Something strange with the coordinate system or why am I getting minus-coordinates?

Translate
Peter5C40Author
Participant
Oct 15, 2020 7:59 PM UTC

I think the problem is that the page is rotated (270) and that's why the coordinate system is off. Is it possible to change the rotation of the coordinate system without actually rotating the page.

Translate