Skip to content

Latest commit

 

History

History
54 lines (41 loc) · 1.44 KB

modify-form-fields.md

File metadata and controls

54 lines (41 loc) · 1.44 KB
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

Description

You have a document that has many form fields and you want to populate them with data in the code.

Solution

You can import the document and iterate all fields. This will allow you to set their value.

C#

{{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}}