Skip to main content
deinonychus
Participant
November 9, 2022
Question

Alternate text field placement depending on page orientation

  • November 9, 2022
  • 1 reply
  • 344 views

I've been using Acrobat JavaScript for a long time to insert text fields, but I'm having a problem inserting them at the top of the page with alternative page orientations (portrait & landscape) because sometimes the landscape orientations push them off the page.

I found another thread that said it the width of a landscaped page is greater than 800 points, so I tried this If/Then function, but it didn't work.

for (var pageNumber = 0; pageNumber < this.numPages; pageNumber++)
var aRect = this.getPageBox("Media");
var width = aRect[2] - aRect[0];
var height = aRect[1] - aRect[3];

if (width<800)
// Insert the Uncontrolled Copy field into Portrait header.
{ 
var p = this.addField("stpUnc","text",pageNumber,[252,785,372,767]); p.textFont= "Arial"; p.textColor=color.red; p.textSize=12; p.alignment= "center"; p.readonly = true;
this.getField('stpUnc').value = s;
}
else
{
// Insert the Uncontrolled Copy field into Landscape header.
{ 
var l = this.addField("stpUnc","text",pageNumber,[330,785,372,767]); l.textFont= "Arial"; l.textColor=color.red; l.textSize=12; l.alignment= "center"; l.readonly = true;
this.getField('stpUnc').value = s;
}}

 

This topic has been closed for replies.

1 reply

Bernd Alheit
Community Expert
Community Expert
November 10, 2022

At Prepare Form add a text field to the page and check the coordinates of the field.