Articles in this section
Category / Section

How to rename form fields in an existing document.

1 min read

It is possible to rename the form fields in a pdf document by using “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 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 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

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