Some test text!

Create new form fields and widget annotations

Contents

Learn more accessing interactive fields
Understanding field types
Creating form fields

To create new form fields and widget annotations within a new document.

// Create a blank page
PDFDoc doc = new PDFDoc();
Page blank_page = doc.PageCreate();

// Create a new field (aka AcroForms).
Field emp_first_name = doc.FieldCreate("employee.name.first", Field.Type.e_text, doc.CreateIndirectString("John"));

// Create text annotation
Annots.Widget annot = Annots.Widget.Create(doc, new Rect(50, 550, 350, 600), emp_first_name);

// Add annotation to the page
blank_page.AnnotPushBack(annot);  

// Add the page as the last page in the document.
doc.PagePushBack(blank_page);

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

linkLearn more accessing interactive fields

The form shown in the following figure consists of a number of Fields:

Every field has its name and value, as well as its annotation appearance.

In the PDFTron SDK, Fields are accessed through FieldIterators.

For example, the list of all Fields present in the document can be traversed using the following code snippet:

FieldIterator itr;
for(itr=doc.GetFieldIterator(); itr.HasNext(); itr.Next())
{
  Field field = itr.Current();
  Console.WriteLine("Field name: {0}",field.GetName());
}

linkUnderstanding field types

PDF offers six different field types. Each type of form field is used for a different purpose, and they have different properties, appearances, options, and actions that can be associated with the fields. In this section, we will explain how to create all the seven field types and some attributes specific to each one.

Common field types are text-box, checkbox, radio-button, combo-box, and push-button. To find out the type of the Field use Field.GetType() method:

Field.FieldType type = field.GetType();
switch(type)
{
case Field.FieldType.e_button:
  Console.WriteLine("Button");
  break;
case Field.FieldType.e_check:
  Console.WriteLine("Check");
  break;
case Field.FieldType.e_radio:
  Console.WriteLine("Radio");
  break;
case Field.FieldType.e_text:
  Console.WriteLine("Text");
  break;
case Field.FieldType.e_choice:
  Console.WriteLine("Choice");
  break;
case Field.FieldType.e_signature:
  Console.WriteLine("Signature");
  break;
}

linkCreating form fields

Regardless of which field type you create, you must provide a Field name:

Field myField = doc.FieldCreate("address", Field.Type.e_text);

Under most circumstances, field names must be unique. If you have a field you name as "address" and you create a second field you likewise call "address", you cannot supply different data in the two fields.

Field names can use alphanumeric characters to identify a field. All field names are case-sensitive. For example, you can use names such as empFirstName, empSecondName, empNumber, and so on for a group of fileds that are related to the same concept (in our sample employee entity).

Another technique for naming fields is to use a parent and child name. For example, you could name the above fields as follows: employee.name.first, employee.name.second, employee.number.

This naming convention is not only useful for organizing purposes but is well-suited for automatic operations on Fields. In the PDFTron SDK, Field.GetName() returns a string representing the fully qualified name of the field (e.g. "employee.name.first"). To get the child name ("first") use the Field.GetPartialName() method.

For more information about adding Fields, see the FDF code sample.

Get the answers you need: Support

Contents

Learn more accessing interactive fields
Understanding field types
Creating form fields