• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Place static stamp with javascript

New Here ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript

Views

1.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 15, 2020 Oct 15, 2020

Copy link to clipboard

Copied

No, you'll have to recreate the page.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 21, 2020 Oct 21, 2020

Copy link to clipboard

Copied

How do I recreate the page? I have found out that most drawings are being scanned and then rotated and I am not finding a way to place my stamp correctly if the page is rotated. I am not able to control how the pdf:s are being scanned and rotated because it is out of our control so I have to find I way to rotate the coordinate system or reset pdf to be able to use my script. Any ideas?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 21, 2020 Oct 21, 2020

Copy link to clipboard

Copied

LATEST

The stamp needs to be set to the page rotation. 

This article explains PDF page coordinates.

https://www.pdfscripting.com/public/PDF-Page-Coordinates.cfm

You can also find everything you need to know about stamps, including automation, here:

https://www.pdfscripting.com/public/All_About_PDF_Stamps.cfm

 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines