Instead of rename many fields -> Add and remove fields
Hello everybody,
I created a form from an Excel sheet. Acrobat has badly named many fields. I don't want to rename them all by hand. Instead I want to "read" the original fields, create a new one with a different name in the same position and then delete the old one.
I would like to test this in 12 fields (there is one on each of the 12 pages of the form). When creating the form, they were named as follows: Name / Name_2 / Name_3 / ... / Name_12.
To do this, I tried the following code in the console:
for(var i = 0; i < this.numFields; i++){
var fName = this.getNthFieldName(i);
if(fName.indexOf("Name") !== -1){
var f = this.getField(fName);
var fCoords = [];
var fPage = (f.page + 1);
fCoords = f.rect;
this.addField(("Name." + fPage), "text", f.page, fCoords);
this.removeField(f.name);
fCoords.length = 0;
}
}
It works as it should on 10 pages.
Only on page 1 (.page 0 / .name: "Name") and on page 10 (.page 9 / .name: "Name_10") not. On page 1, the field is only deleted, but no new one is created. Nothing happens on page 10. The Name_10 field remains and no new field is created.
I don't understand why this happens and would be very happy if someone can explain it to me and how I can solve the problem or do it better.
Thanks in advance for your help.
