Some test text!
iOS / Guides / Create form fields
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 text field and text widget/annotation (aka AcroForms).
PTField *text_field = [doc FieldCreateWithString: @"employee.name" type: e_pttext field_value: @"" def_field_value: @""];
PTTextWidget *text = [PTTextWidget CreateWithField: doc pos: [[PTPDFRect alloc] initWithX1: 110 y1: 620 x2: 380 y2: 650] field: text_field];
[text SetFont: [PTFont Create: [doc GetSDFDoc] type: e_pttimes_bold embed: NO]];
[text RefreshAppearance];
[blank_page AnnotPushBack: text];
// Create a new signature field and signature annotation (aka AcroForms)
PTDigitalSignatureField* sig_field = [doc CreateDigitalSignatureField: @"employee.signature"];
PTSignatureWidget* signature = [PTSignatureWidget CreateWithDigitalSignatureField: doc pos: [[PTPDFRect alloc] initWithX1: 0 y1: 100 x2: 200 y2: 150] field: sig_field];
[signature RefreshAppearance];
[blank_page AnnotPushBack: signature];
// Create a new checkbox field and checkbox widget/annotation (aka AcroForms)
PTCheckBoxWidget *checkbox = [PTCheckBoxWidget Create: doc pos: [[PTPDFRect alloc] initWithX1: 190 y1: 490 x2: 250 y2: 540] field_name: @"employee.checkbox"];
[checkbox SetBackgroundColor: [[PTColorPt alloc] initWithX: 1 y: 1 z: 1 w: 0] compnum: 3];
[checkbox SetBorderColor: [[PTColorPt alloc] initWithX: 0 y: 0 z: 0 w: 0] compnum: 3];
[checkbox SetChecked: true]; // Check the widget (by default it is unchecked).
[checkbox RefreshAppearance];
[blank_page AnnotPushBack: checkbox];
// Create a radio button group and add three radio button widget/annotation (aka AcroForms) in it.
PTRadioButtonGroup *radio_group = [PTRadioButtonGroup Create: doc field_name: @"employee.radiogroup"];
PTRadioButtonWidget *radiobutton1 = [radio_group Add: [[PTPDFRect alloc] initWithX1: 140 y1: 410 x2: 190 y2: 460] onstate: @""];
[radiobutton1 SetBackgroundColor: [[PTColorPt alloc] initWithX: 1 y: 1 z: 0 w: 0] compnum: 3];
[radiobutton1 RefreshAppearance];
PTRadioButtonWidget *radiobutton2 = [radio_group Add: [[PTPDFRect alloc] initWithX1: 310 y1: 410 x2: 360 y2: 460] onstate: @""];
[radiobutton2 SetBackgroundColor: [[PTColorPt alloc] initWithX: 0 y: 1 z: 0 w: 0] compnum: 3];
[radiobutton2 RefreshAppearance];
PTRadioButtonWidget *radiobutton3 = [radio_group Add: [[PTPDFRect alloc] initWithX1: 480 y1: 410 x2: 530 y2: 460] onstate: @""];
[radiobutton3 EnableButton]; // Enable the third radio button. By default the first one is selected
[radiobutton3 SetBackgroundColor: [[PTColorPt alloc] initWithX: 0 y: 1 z: 1 w: 0] compnum: 3];
[radiobutton3 RefreshAppearance];
[radio_group AddGroupButtonsToPage: blank_page];
// 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).
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 Apryse 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 .
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;
}
Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales