How can I randomize the position of a stamp on PDF using Javascript

How can I randomize the position/rotation of a stamp on PDF using Javascript


I have a PDF to which I need to apply a stamp on every page, but I would like to add some kind of variation (like it was applied manually).

What should I add to this code in order to add a small randomize number to the initial position and rotation of the stamp?

The current code:

var annt = this.getAnnots(this.pageNum)[0];
var props = annt.getProps();
for(var i=0;i < this.numPages;i++){ = i;
if(i != this.pageNum)

Thank you.

Later edit: I think I didn’t choose the right section to post my question. Sorry.

It’s a Front End question, you’re fine. It’s just difficult to see from your code which values you’d like to randomise.

Let’s say you have an xPos coordinate, and you want it to change between xPos and xPos + offset, where offset gets assigned to a random value. It could be 0 or it could be, for example, 100 (px or whatever).

A way to do that in JavaScript would be:
let offset = Math.floor(Math.random() * 101);

If you have an angle that you’d like to change randomly from -20° and 20°, that would be:
let angleOffset = Math.floor(Math.random() * 41) - 20;