Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Jun 22, 2016 3:16 am

Hi,
I'm trying to change name of PDF Form Field, but i don't find any way to do it. Please help me.
My case
- Opening exist file -> read all pdf form fields -> change name

Long

longt@avantility.com
 
Posts: 2
Joined: Tue Jun 21, 2016 7:01 am

Wed Jun 22, 2016 3:52 am

Hi Long,

Thanks for your posting.
Please refer to the following code to finish your project.
Code: Select all
   PdfDocument pdf = new PdfDocument();
            pdf.LoadFromFile(input);
            PdfFormWidget form = pdf.Form as PdfFormWidget;
            for (int i = 0; i < form.FieldsWidget.List.Count; i++)
            {
                PdfField field = form.FieldsWidget.List[i] as PdfField;
                if (field is PdfTextBoxFieldWidget)
                {
                    PdfTextBoxFieldWidget textbox = field as PdfTextBoxFieldWidget;
                    if (textbox.Name == "Text1")
                    {
                          //change name of field
                         textbox.SetName("Name1");
                    }
               }
           }

Welcome to write to us again if you need further assistance.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Wed Jun 22, 2016 8:36 am

Many thanks for supporting me
Long

longt@avantility.com
 
Posts: 2
Joined: Tue Jun 21, 2016 7:01 am

Thu Jun 23, 2016 1:50 am

Welcome to write to us again if you need further help.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Thu Aug 22, 2019 7:35 pm

This does not work if your field name has a period in it. I had field names where InDesign added a .Page N to each field on a footer, where N was the page number. Changing a field name that has a period in it, does not work properly due to the implied hierarchy. The work around is to copy the details of the field into a new field and then remove the old one and add the new one. Since I was already looping through all the fields, I saved a list of fields to remove and fields to add. It would be nice if Spire.PDF supported renaming fields with periods in it. :D

Example of field rename that does not work: Old name {Part1}Part_2{Part_3}.Page 3, try to rename this to {Part1}Part_2_Page_3{Part_3} but instead you get: {Part1}Part_2{Part_3}. {Part1}Part_2_Page_3{Part_3} for a new name of the field. In fact, you're just renaming the part after the period.

JohnPela
 
Posts: 1
Joined: Thu Aug 22, 2019 7:22 pm

Fri Aug 23, 2019 10:42 am

Hi JohnPela,

Thanks for your inquiry.
To help us investigate further, please provide your input PDF, the code you used and the output file.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.PDF