Change all fields of a certain type in Acrobat, to a different type

Here is a handy little script I recently wrote to automate a monotonous task in Acrobat.

Since Acrobat has no method of actually changing field types, you have to remove all fields and add new ones in place. This script gets the coordinates of the existing fields and replaces them in exactly the same spot with new fields.

Just change the fieldTypeToChange variable to whatever you need to change and change the newFieldType to whatever field type you want to switch to. I attach this to a button then press when I'm ready. Depending on what field type you are changing to, you may need to add some new field properties. If you have questions, post them in the comments section.

Here is the code:

var fieldTypeToChange = "signature";
var newFieldType = "text";

for (var fieldNumber = 0; fieldNumber  < numFields; fieldNumber ++)
{
  var thisField = getField(getNthFieldName(fieldNumber));    
  if(thisField.type == fieldTypeToChange){
    var aRect = thisField.rect;
    var newField = addField(thisField.name+"fieldNumber", newFieldType, thisField.page, aRect);
    removeField(thisField.name);

  }
}