Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Engaged ,
Oct 13, 2025 Oct 13, 2025

 

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
 
 

 

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
TOPICS
JavaScript , PDF forms
116
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
Community Expert ,
Oct 13, 2025 Oct 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

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 13, 2025 Oct 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Oct 13, 2025 Oct 13, 2025
LATEST

Thank you very much @JR Boulay 

Thanks,
Prabu
Design smarter, faster, and bolder with InDesign scripting.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines