title | description | type | page_title | slug | position | tags | res_type |
---|---|---|---|---|---|---|---|
Iterate and modify form fields in code |
Learn how to iterate and modify form fields in code using PdfProcessing. |
how-to |
Iterate and modify form fields in code |
modify-form-fields |
0 |
form, fields, modify |
kb |
Product Version | Product | Author |
---|---|---|
2020.1.218 | RadPdfProcessing | Dimitar Karamfilov |
You have a document that has many form fields and you want to populate them with data in the code.
You can import the document and iterate all fields. This will allow you to set their value.
{{region kb-modify-form-fields_0}}
var provider = new PdfFormatProvider();
var document = provider.Import(File.ReadAllBytes("form_doc.pdf"));
foreach (RadFixedPage page in document.Pages)
{
foreach (Annotation annotation in page.Annotations)
{
if (annotation.Type == AnnotationType.Widget)
{
Widget widget = (Widget)annotation;
var field = widget.Field as TextBoxField;
if (field != null)
{
if (field.Name == "Name")
{
field.Value = "John Doe";
}
}
}
}
}
File.WriteAllBytes("result.pdf", provider.Export(document));
{{endregion}}