Some test text!

Filling in form fields


About filling form fields

To fill in values for existing form fields.

PDFDoc doc = new PDFDoc(filename);

// Search for a specific field
Field fld = doc.GetField("");

PDF Interactive Forms (AcroForms)
Full code sample which illustrates some basic PDFNet capabilities related to interactive forms (also known as AcroForms).

linkAbout filling form fields

Form Fields can be populated using the Field.SetValue() method:

field.SetValue("New Value");

// Regenerate appearance stream.

Note that, after modifying the Field's value, we refreshed its appearance stream. In the PDF format, Field's value and appearance are two different entities. Therefore, if you don't call RefreshAppearance(), the initial value on a PDF page will remain unchanged — it may have retain the old value or it may be blank.

One approach used by other PDF libraries is to let the PDF viewer automatically pre-generate appearance streams by setting the 'NeedAppearances' flag in AcroForm dictionary:

doc.GetAcroForm().PutBool("NeedAppearances", true);

This will force viewer applications to auto-generate appearance streams every time the document is opened. This method is unreliable — Acrobat does not always generate appearance streams correctly. Another disadvantage of this approach is that the user will always be prompted to save the document even if the document was never modified.

Field.GetValueAsString() returns the field's value as a string. The value returned varies based on the field type. A text field type varies depending on the field type. A text field will return a string:

if (type == Field.FieldType.e_text && field.GetValue())
  Console.WriteLine("Field value: {0}", field.GetValueAsString());
  Console.WriteLine("Field is blank");

Other field types, such as check boxes and radio buttons, can also return text from GetValueAsString(). Similarly, the Field.GetValueAsString() method is available.

Get the answers you need: Support


About filling form fields