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

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

  • October 13, 2025
  • 1 reply
  • 182 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
Community Expert
JR BoulayCommunity ExpertCorrect answer
Community Expert
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
Legend
October 13, 2025

Thank you very much @JR Boulay 

Design smarter, faster, and bolder with InDesign scripting.