Skip to main content
Participating Frequently
August 10, 2025
Répondu

Changing the .rotation of all widgets of a form text field in a multipage document

I used the elegant script at https://community.adobe.com/t5/acrobat-discussions/script-that-applies-f-setaction-to-text-fields-with-specific-names-using-some-type-of-wildcard/m-p/15452287#M516095 to successfully rotate my form text fields 90°, but I must be missing something about how to iterate this over all of the pages in the document. It is only acting on the first page of the document. Do I need to push the widgets for each field to an array? Is there a way to use javascript to "duplicate the fields across pages" as in the right-click field menu? Thank you for any advice.

 

var pRot = this.getPageRotation();

for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f==null) continue;
if (f.type=="text") {
f.rotation = pRot + 90;
   }
}

 

I also tried this -

 

for (var p=0; p<this.numPages; p++) {
var pRot = this.getPageRotation(p);
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f==null) continue;
if (f.type=="text") {
f.rotation = pRot + 90;
      }
   }
}


Meilleure réponse par Nesa Nurani

Script to add fields and set rotation:

var fields = [
 {name: "customer", coords: [200, 100, 225, 200]},
 {name: "address", coords: [230, 100, 255, 200]},
 {name: "city st zip", coords: [260, 100, 285, 200]}
];

for(var i=0; i<fields.length; i++) {
 var fData = fields[i];
 for (var p = 0; p < this.numPages; p++) {
  this.addField(fData.name, "text", p, fData.coords);
  this.getField(fData.name + "." + p).rotation = 90;}}

2 commentaires

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertRéponse
Community Expert
August 11, 2025

Script to add fields and set rotation:

var fields = [
 {name: "customer", coords: [200, 100, 225, 200]},
 {name: "address", coords: [230, 100, 255, 200]},
 {name: "city st zip", coords: [260, 100, 285, 200]}
];

for(var i=0; i<fields.length; i++) {
 var fData = fields[i];
 for (var p = 0; p < this.numPages; p++) {
  this.addField(fData.name, "text", p, fData.coords);
  this.getField(fData.name + "." + p).rotation = 90;}}
Thom Parker
Community Expert
Community Expert
August 10, 2025

Fields don't have page associations. In fact the fields don't exist on pages at all. They exist in a special structure at the document level. What you see on the pages are the widgets. The "getField" function gets the field object, and the properties for the first widget.  The other widgets have to be gotten using a modified field name.  

 

If the field is named "TestField" then the first widget is "TestField.0", and the second widget is "TestField.1".  The number of widgets is provided in the field's "page" property. If the field has more than one widget, then the page property will be an array of page numbers, one for each widget. 

So, your script needs to be modified to get the number of widgets after it acquires the field, then call "getField" for each individual widget.  The script could also use the page number to get the correct rotation for page the widget is on. 

 

 

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Participating Frequently
August 10, 2025

Thom, 

Thank you for your reply. I understand the concepts you've explained above and your suggestions are exactly the issues I have identified, but have been unable to solve how to implement successfully.  Would it be possible for you to provide an example solution on your website or to point me toward the relevant tutorials? 

Participating Frequently
August 10, 2025

I initially posted this as reply on another thread. Unfortunately, there are now two discussions in process. More info here - Solved: Script that applies f.setAction to text fields wi... - Adobe Product Community - 14501354