Skip to main content
Participant
February 6, 2025
Question

Automatically place custom stamp - guided action

  • February 6, 2025
  • 1 reply
  • 229 views

Greetings! So basically I would like to automate a manual process I sometimes do hundreds of times a day. I have to manually place a stamp onto PDF's, so I wanted to create a guided action that automatically places it in the top right corner of a page. My javascript skills are lacking, and below is my code in the guided action. I can't figure out the placement as this just puts it in the bottom, and it also only selects the most recent stamp I used. Would anyone know how to update the code to place a specific custom stamp in the top right of a page? Here is my code:

var stampName = "jp#test_stamp";

var pageWidth = this.getPageBox("Crop", 0)[2];

var pageHeight = this.getPageBox("Crop", 0)[3];

var stampWidth = 200; var stampHeight = 100;

var x = pageWidth / 2 - stampWidth / 2;

var y = pageHeight / 2 - stampHeight / 2;

 

this.addAnnot({

   page: 0,

   type: "Stamp",

   rect: [x, y, x + stampWidth, y + stampHeight],

   name: stampName

});

1 reply

PDF Automation Station
Community Expert
Community Expert
February 6, 2025

pageHeight should be var pageHeight = this.getPageBox("Crop", 0)[1]; (Crop box coordinates start on the left and go clockwise, annotation rect coordinates start on the left and go counter clockwise, so the tops and bottoms are reversed).

 

this.addAnnot({

   page: 0,

   type: "Stamp",

   rect: [pageWidth-stampWidth, pageHeight-stampHeight, pageWidth, pageHeight],

   AP: stampName

});

 

FYI, if the AP does not start with #, you will have problems applying the stamp after the first application.