<!--
{
  "documentType" : "article",
  "framework" : "PDFKit",
  "identifier" : "/documentation/PDFKit/adding-widgets-to-a-pdf-document",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Adding Widgets to a PDF Document"
}
-->

# Adding Widgets to a PDF Document

Add text, button, and choice widgets to a PDF document.

## Discussion

Widgets are interactive form elements that you can add to a PDF to make it easier to enter and submit information. Widgets are a special annotation subtype. To learn more about non-interactive custom annotations, see [Adding Custom Graphics to a PDF](/documentation/PDFKit/adding-custom-graphics-to-a-pdf).

Each widget type has several variations. A button can be a radio button, a check box, or a push button. A choice widget can be a list box, which is a table of options, or a combo box, which is like a dropdown.

![Add widgets to create a form in a PDF.](images/com.apple.pdfkit/media-3039567@2x.png)

### Create a Widget Annotation

Create a PDF annotation of type [`widget`](/documentation/PDFKit/PDFAnnotationSubtype/widget). This example initializes a widget annotation with rectangular bounds:

```swift
let radioButton = PDFAnnotation(bounds: CGRect(x: 135, y: 200, width: 24, height: 24), forType: .widget, withProperties: nil)
```

### Specify a Field Type and a Control Type

Specify a [`widgetFieldType`](/documentation/PDFKit/PDFAnnotation/widgetFieldType) that is a [`PDFAnnotationWidgetSubtype`](/documentation/PDFKit/PDFAnnotationWidgetSubtype). The three different subtypes are [`text`](/documentation/PDFKit/PDFAnnotationWidgetSubtype/text), [`button`](/documentation/PDFKit/PDFAnnotationWidgetSubtype/button), and [`choice`](/documentation/PDFKit/PDFAnnotationWidgetSubtype/choice). Here you will create a button widget for the radio button:

```swift
radioButton.widgetFieldType = .button
```

Set the widget control type. For a button widget, there are three possible control types: [`PDFWidgetControlType.radioButtonControl`](/documentation/PDFKit/PDFWidgetControlType/radioButtonControl), [`PDFWidgetControlType.checkBoxControl`](/documentation/PDFKit/PDFWidgetControlType/checkBoxControl), and [`PDFWidgetControlType.pushButtonControl`](/documentation/PDFKit/PDFWidgetControlType/pushButtonControl).

```swift
radioButton.widgetControlType = .radioButtonControl
```

### Adjust Widget Properties

Adjust properties to highlight the widget so it is more visible. The following example adds a blue background to a radio button widget.

```swift
radioButton.backgroundColor = UIColor.blue
```

Properties will be different depending on the field type. If you have multiple radio buttons and want to group them together, specify the same [`fieldName`](/documentation/PDFKit/PDFAnnotation/fieldName) property. Specify different [`buttonWidgetStateString`](/documentation/PDFKit/PDFAnnotation/buttonWidgetStateString) properties for each button if you should only select one at a time. For a text field, you can use [`widgetStringValue`](/documentation/PDFKit/PDFAnnotation/widgetStringValue) to specify placeholder text and [`font`](/documentation/PDFKit/PDFAnnotation/font) to specify the font of the field’s text.

### Add the Annotation to Your PDF

Add the annotation to the page.

```swift
page.addAnnotation(radioButton)
```

You can combine many different kinds of widgets on your PDF. Using a combination of widgets can help you turn a PDF document into an interactive form. For more details on widget options, see [`PDFAnnotation`](/documentation/PDFKit/PDFAnnotation).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)