Some test text!

menu
Create form fieldskeyboard_arrow_down

Create new form fields and widget annotations

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

// Create a blank page
PTPDFDoc *doc = [[PTPDFDoc alloc] init];        
PTPage *blank_page = [doc PageCreate: [[PTPDFRect alloc] initWithX1: 0 y1: 0 x2: 612 y2: 792]];

// Create a new field (aka AcroForms).
PTField *emp_first_name = [doc FieldCreateWithString: @"employee.name.first" type: e_pttext field_value: @"John" def_field_value: @""];

// Create text annotation
PTTextWidget *text = [PTTextWidget CreateWithField: doc pos: [[PTPDFRect alloc] initWithX1: 110 y1: 620 x2: 380 y2: 650] field: emp_first_name];
[text SetFont: [PTFont Create: [doc GetSDFDoc] type: e_pttimes_bold embed: NO]];
[text RefreshAppearance];

// Add annotation to the page
[blank_page AnnotPushBack: text];

// 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).

linkAbout creating form fields

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

PTField *my_field = [doc FieldCreate: @"address" type: e_pttext];

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.

linkUnderstand 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:

PTFieldType type = [field GetType];
switch(type)
{
  case e_ptbutton: 
    printf("Button");
    break;
  case e_ptcheck:
    printf("Check");
    break;
  case e_ptradio:
    printf("Radio");
    break;
  case e_pttext: 
    printf("Text")
    break;
  case e_ptchoice: 
    printf("Choice");
    break;
  case e_ptsignature: 
    printf("Signature");
    break;
  default: 
    break;
}

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

Join our live demo to learn about use cases & capabilities for WebViewer

Learn more
close