Skip to main content
Anantha Prabu G
Braniac
October 13, 2025
Answered

How to remove spaces from PDF form field names using a script?

  • October 13, 2025
  • 1 reply
  • 134 views

 

Hi everyone,

I have a PDF with multiple form fields, some of which have spaces in their names (e.g., Text Field 1). I want to rename them to remove spaces (e.g., TextField1).

I tried using Acrobat Javascript:

 

 
for (var i = 0; i < this.numFields; i++) {
    var oldName = this.getNthFieldName(i);
    var newName = oldName.replace(/\s+/g, "");
    this.renameField(oldName, newName); // Throws TypeError
}
…but I get this error:

TypeError: this.renameField is not a function
 
 

 

Correct answer JR Boulay

"renameField" is not a function.

A field cannot be renamed directly. You must save its properties, delete the existing field, and recreate another one in the same place.
The disadvantage is that the field's actions, format, etc. are lost during this process.
You should use this script: https://vielhuber.de/en/blog/rename-pdf-form-fields-en-masse/

1 reply

JR Boulay
JR BoulayCorrect answer
Braniac
October 13, 2025

"renameField" is not a function.

A field cannot be renamed directly. You must save its properties, delete the existing field, and recreate another one in the same place.
The disadvantage is that the field's actions, format, etc. are lost during this process.
You should use this script: https://vielhuber.de/en/blog/rename-pdf-form-fields-en-masse/

Acrobate du PDF, InDesigner et Photoshopographe
Anantha Prabu G
Braniac
October 13, 2025

Thank you very much @JR Boulay 

Thanks,PrabuDesign smarter, faster, and bolder with InDesign scripting.