iOS
ComPDFKit PDF SDK
Guides

Fill Form Fields

 

ComPDFKit PDF SDK fully supports the AcroForm standard, and forms can be viewed and filled inside the CPDFView.

 

To fill in a text form element, tap it and then type text using either the onscreen keyboard or an attached hardware keyboard. Then tap either the Done button above the keyboard or any blank area on the page to deselect the form element, which will commit the changes.

 

 

To set the value of a choice form element (a list or combo box), tap the element, and then select an item from the list, or type in a custom item.

 

 

To enable or disable a checkbox form element, tap it to toggle its state. And you can set the selection of a radio button form element by tapping the desired item.

 

 

 

While a form element is selected (focused), the left and right arrows above the keyboard may be used to move the focus sequentially between all the form elements on the page.

 

The following example demonstrates how form fields can be queried and filled with code:

 

NSURL *url = [NSURL fileURLWithPath:pdfPath];
CPDFDocument *document = [[[CPDFDocument alloc] initWithURL:url] autorelease];
CPDFPage *page = [document pageAtIndex:0];
​
NSArray *annotations = [page annotations];
for (CPDFAnnotation *annotation in annotations) {
   if ([annotation isKindOfClass:[CPDFTextWidgetAnnotation class]]) {
      [(CPDFTextWidgetAnnotation *)annotation setStringValue:@""];
  } else if ([annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]]) {
       if (CPDFWidgetRadioButtonControl == [(CPDFButtonWidgetAnnotation *)annotation controlType]) {
          [(CPDFButtonWidgetAnnotation *)annotation setState:1];
      }
  } else if ([annotation isKindOfClass:[CPDFChoiceWidgetAnnotation class]]) {
      [(CPDFChoiceWidgetAnnotation *)annotation setSelectItemAtIndex:0];
  }
}