I am working on a Javascript plugin for adobe acrobat. The goal is to add a field with version specific text to each field. The wrinkle is that pages are of different sizes, and some are in portrait and others in landscape, and I need to put the stamp in the appropriate orientation and position for each.
I've solved most of this, but have one problem. When the person creates the PDF pages (from a CAD program) in their final orientations, my code (below) works correctly. If, however they create a page as landscape, and then use the 'rotate page' feature in Adobe Acrobat to make it appear portrait, the stamp shows up in the correct position, but 90 degrees off from the orientation I want. (The bounding box is also 90 degrees off, causing the text to be very small.)
How can I detect if a page has been rotated like this so I can set the field orientation correctly. Alternately, can I designate the field using a separate coordinate place that is not effected by rotation?
My code so far is:
function versionStamp()
{
var oCurrentDate = new Date();
var inch = 72;
var newVersionLetter = app.response({
cQuestion: "What is the new version letter?",
cTitle: "Enter Version Letter",
cDefault: " ",
cLabel: "Rev",
});
if (newVersionLetter != null)
{
this.removeField("dateField");
for (var p = 0; p < this.numPages; p++) {
var aRect = this.getPageBox( {nPage: p} );
var width = aRect[2] - aRect[0];
var fieldCreated = false;
if (width == (11*inch))
{
aRect[0] += 1.1*inch;
aRect[2] = aRect[0] - 36;
aRect[1] -= 16.6*inch;
aRect[3] = aRect[1] + 1*inch;
newDateField = this.addField("dateField" + "." + p, "text", p, aRect);
newDateField.rotation = 270;
fieldCreated = true;
}
if (width == (17*inch))
{
aRect[0] += 15.57*inch;
aRect[2] = aRect[0]+1*inch;
aRect[1] -= 9.875*inch;
aRect[3] = aRect[1] - 36;
newDateField = this.addField("dateField" + "." + p, "text", p, aRect);
fieldCreated = true;
}
if (width == (24*inch))
{
aRect[0] += 1.8*inch;
aRect[2] = aRect[0] - 36;
aRect[1] -= 34.9*inch;
aRect[3] = aRect[1] + 1.75*inch;
newDateField = this.addField("dateField" + "." + p, "text", p, aRect);
newDateField.rotation = 270;
fieldCreated = true;
}
if (width == (36*inch))
{
aRect[0] += 33.17*inch;
aRect[2] = aRect[0]+1.75*inch;
aRect[1] -= 22.2*inch;
aRect[3] = aRect[1] - 36;
newDateField = this.addField("dateField" + "." + p, "text", p, aRect);
fieldCreated = true;
}
if (fieldCreated)
{
newDateField.textColor = color.red
newDateField.value = util.printd("mm/dd/yy", oCurrentDate) + " " + util.printd("HH:MM", oCurrentDate) + " " + newVersionLetter;
newDateField.readonly = true;
}
}
}
}
Have you tried getting the page rotation value from the page and then adjusting the orientation of your stamp based on the return value?
Per Acrobat Documentation Page 127.
getPageRotation will return you 0, 90, 180, or 270 depending on how the page was rotated. Then you can use that value to adjust the location of your stamp.
var rotation = this.getPageRotation(3); //get rotation of page 3
if(rotation)
{
//Depending on the value, adjust location of stamp
}