> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/ios/forms/new-fields.md).

# Create new form fields and widget annotations on iOS

Learn how to create new form fields and widget annotations in a PDF document. Get a full code sample illustrating PDFNet capabilities for interactive forms (AcroForms) and understand field types. Crea

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

{% tabs %}
{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
// 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];
```

{% endcode %}
{% endtab %}

{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
// Create a blank page
let doc: PTPDFDoc = PTPDFDoc()
let blank_page: PTPage = doc.pageCreate(PTPDFRect(x1: 0, y1: 0, x2: 612, y2: 792))

// Create a new text field and text widget/annotation (aka AcroForms).
let text_field: PTField = doc.fieldCreate(with: "employee.name", type: e_pttext, field_value: "", def_field_value: "")
let text: PTTextWidget = PTTextWidget.create(withField: doc, pos: PTPDFRect(x1: 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()
blank_page.annotPushBack(text)

// Create a new signature field and signature annotation (aka AcroForms)
let sig_field: PTDigitalSignatureField = doc.createDigitalSignatureField("employee.signature")
let signature: PTSignatureWidget = PTSignatureWidget.create(withDigitalSignatureField: doc, pos: PTPDFRect(x1: 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)
let checkbox_field: PTField = doc.fieldCreate(with: "employee.checkbox", type:e_ptcheck, field_value: "Yes", def_field_value: "")
let checkbox: PTCheckBoxWidget = PTCheckBoxWidget.create(withField:doc, pos: PTPDFRect(x1: 190 , y1: 490 , x2: 250, y2:540) field:checkbox_field)
checkbox.setBackgroundColor(PTColorPt(x: 1, y: 1, z: 1), compnum: 3)
checkbox.setBorderColor(PTColorPt(0.0, 0.0, 0.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.
let radio_group: PTRadioButtonGroup = PTRadioButtonGroup.create(doc, "employee.radiogroup")
let radiobutton1: PTRadioButtonWidget = radio_group.add(PTPDFRect(x1: 140, y1: 410, x2: 190, y2: 460), onstate: "")
radiobutton1.setBackgroundColor(PTColorPt(x: 1, y: 1, z: 1), compnum: 3)
radiobutton1.refreshAppearance()
let radiobutton2: PTRadioButtonWidget = radio_group.add(PTPDFRect(x1: 310, y1: 410, x2: 360, y2: 460), onstate: "")
radiobutton2.setBackgroundColor(PTColorPt(x: 0, y: 1, z: 0), compnum: 3)
radiobutton2.refreshAppearance()
let radiobutton3: PTRadioButtonWidget = radio_group.add(PTPDFRect(x1: 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(x: 0, y: 1, z: 1), compnum: 3)
radiobutton3.refreshAppearance()
radio_group.addGroupButtonsToPage(blank_page)

// Add the page as the last page in the document.
doc.pagePushBack(blank_page)
```

{% endcode %}
{% endtab %}
{% endtabs %}

[PDF interactive forms (AcroForms)](/ios/get-started/samples.md#interactiveforms) Full code sample which illustrates some basic PDFNet capabilities related to interactive forms (also known as AcroForms).

## About creating form fields

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

{% tabs %}
{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

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

{% endcode %}
{% endtab %}

{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
let my_field: PTField = doc.fieldCreate("address", type: e_pttext)
```

{% endcode %}
{% endtab %}
{% endtabs %}

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 ](/ios/get-started/samples.md#fdf).

## Understand 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:

{% tabs %}
{% tab title="Obj-C" %}
{% code lineNumbers="true" %}

```objc
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;
}
```

{% endcode %}
{% endtab %}

{% tab title="Swift" %}
{% code lineNumbers="true" %}

```swift
let type: PTFieldType = field.getType()
switch type
{
  case e_ptbutton:
      print("Button")
  case e_ptcheck:
      print("Check")
  case e_ptradio:
      print("Radio")
  case e_pttext:
      print("Text")
  case e_ptchoice:
      print("Choice")
  case e_ptsignature:
      print("Signature")
  default:
      break
}
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/ios/forms/new-fields.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
