Java Script not working with custom stamp

The PDF-XChange Viewer for End Users
+++ FREE +++

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

ajtrahan
User
Posts: 2
Joined: Thu Dec 27, 2012 5:49 pm

Java Script not working with custom stamp

Post by ajtrahan »

This code works perfectlly with a standard stamp like "Sold"
but if I try to use any custom stamp, it works but the stamp is invisible, any suggestions?

var nStampWidth = 150;
var nStampHeight = 50;
var nPageMargin = 80;

var rctCrop = this.getPageBox("Crop",this.pageNum);

var rctPlacement = [];
rctPlacement[0] = rctCrop[2] - nStampWidth - nPageMargin; // Left Side
rctPlacement[1] = nPageMargin; // Bottom Side at page margin
rctPlacement[2] = rctCrop[2] - nPageMargin; // Right side at Page Margin
rctPlacement[3] = nPageMargin + nStampHeight; // Top Side

var mxToDefaultCoords = (new Matrix2D()).fromRotated(this,this.pageNum);
var rectAnnot = mxToDefaultCoords.transform(rctPlacement);

var nPageRot = this.getPageRotation(this.pageNum);

var annot = this.addAnnot({
page:0,
type:"Stamp",
AP:"Sold",
rect:rectAnnot, rotate:nPageRot
});

var copy_props = annot.getProps();

var numpages = this.numPages;
for (var i=0; i < numpages; i++) {
var copy_annot = this.addAnnot(copy_props);
copy_annot.page=i;
}
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3603
Joined: Thu Jul 08, 2004 10:36 pm

Re: Java Script not working with custom stamp

Post by Ivan - Tracker Software »

I'm afraid the problem is with the name you are passing - in the stamps palette user friendly names of the stamps are shown, but for JS you have to specify the real name of the stamp.
For example, when you create a stamp using the viewer, it uses GUIDs as the name of the stamp. Adobe uses a similar method, but with a bit different codding style.

To find the name of the stamp, you can use the following trick: make a new document, place the stamp on the first page and run the following JS:

Code: Select all

console.println(getAnnots(0)[0].AP);
HTH
PDF-XChange Co Ltd. (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
ajtrahan
User
Posts: 2
Joined: Thu Dec 27, 2012 5:49 pm

Re: Java Script not working with custom stamp

Post by ajtrahan »

Works great thanks!
Now I just need to find or write code to get the properties or page location of a placed annotation.

Thanks again!
Nico - Tracker Supp
User
Posts: 205
Joined: Fri May 18, 2012 8:41 pm

Re: Java Script not working with custom stamp

Post by Nico - Tracker Supp »

Hi ajtrahan,

Glad to know that is working.
If you have any questions please feel free to come back.
Thanks.

Sincerely,