Articles in this section
Category / Section

How to rename form fields in an existing document.

4 mins read

It is possible to rename the form fields in a PDF document by using the "SetName()" method.

Assemblies Required

1) Syncfusion.Compression.Base.dll

2) Syncfusion.Pdf.Base.dll

The below code illustrates how to rename form fields in an existing document

Code Snippet:

// Load the PDF document
PdfLoadedDocument ldoc = new PdfLoadedDocument("Form.pdf");

// Creates new PDF Document
PdfDocument doc = new PdfDocument();
// Gets the form from the loaded document
PdfLoadedForm form = ldoc.Form;
// Gets the Form fields
PdfLoadedFormFieldCollection field = form.Fields;

 
// Renaming the form fields
for (int i = 0; i < field.Count; i++)
{
    string name = (form.Fields[i].Name);
    if (name == "topmostSubform[0].Page1[0].f1-1[0]")
        (form.Fields[name] as PdfLoadedTextBoxField).SetName("TextBox 1");
    else if (name == "topmostSubform[0].Page1[0].f1-2[0]")
        (form.Fields[name] as PdfLoadedTextBoxField).SetName("TextBox 2");
    else if (name == "topmostSubform[0].Page1[0].f1-3[0]")
        (form.Fields[name] as PdfLoadedTextBoxField).SetName("TextBox 3");
    else if (name == "topmostSubform[0].Page1[0].f1-4[0]")
        (form.Fields[name] as PdfLoadedTextBoxField).SetName("TextBox 4");
}

doc.Append(ldoc);
// Save the document and dispose of it
doc.Save("sample.pdf");
doc.Close();

 

The Working Sample can be downloaded from the below link:

http://www.syncfusion.com/downloads/support/directtrac/general/RenameFields452908767.zip


Note:

Starting with v16.2.0.x, if you reference Syncfusion&reg; assemblies from a trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion&reg; license key in your application to use the components without a trial message.

 

Conclusion

I hope you enjoyed learning about how to rename form fields in an existing document.

You can refer to our WinForms PDF’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms PDF documentation to understand how to present and manipulate data.

For current customers, you can check out our WinForms components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our WinForms PDF and other WinForms components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied