PlugPDF SDK iOS Developer Guide

How can I detect a touch event in the form field?

In the PlugPDFAnnotEventDelegate, there is a method for detecting touch event from the form field.

Also, you can detect the specific form fields type, such as check box, combo box, radio button, text field and digital signature field.

 - (BOOL)viewController:(UIViewController*)viewController
               onTapUp: (BaseAnnot*)annot
{
       if ([annot isMemberOfClass: PlugPDFButtonField.class]) {
           NSLog (@"form field");
           return NO;
        }
           return YES;
}

Moreover, you can get the form field’s value.

 - (BOOL)viewController: (UIViewController*)viewController
                       onTapUp: (BaseAnnot*)annot
{	
if ([annot isMemberOfClass: PlugPDFTextField.class]) {
	   NSLog(@"%@", ((PlugPDFTextField*)annot).value);
	   return YES;
}
return NO;
}

Not only you can use the tap up event, you can also use the long-press event with the below code.

 - (BOOL)viewController:(UIViewController*)viewController
           onLongPress: (BaseAnnot*)annot
{
    return NO;
}


How can I change the form field’s value programmatically?

You may want to change the form field’s value with default way.

PlugPDF provides some method to set form field’s value.

  • TextField
- (BOOL)viewController: (UIViewController*)viewController
               onTapUp: (BaseAnnot*)annot
{
    if ([annot isMemberOfClass: PlugPDFTextField.class]) {
        NSString *text= @"PlugPDF SDK";
        [[annot document]  setTextFieldWithPage: self.vc.pageIdx
                                          title: ((PlugPDFTextField*)annot).title
                                           text: text];
        return YES;
    }
    return NO;
}
  • Check Box
- (BOOL)viewController: (UIViewController*)viewController
               onTapUp: (BaseAnnot*)annot
{
    if ([annot isMemberOfClass: PlugPDFCheckBoxField.class]) {
        [[annot document]  setCheckBoxFieldWithPage:self.vc.pageIdx
                                              title:((PlugPDFCheckBoxField*)annot).title
                                            checked:((PlugPDFCheckBoxField*)annot).checked];
        return YES;
    }
    return NO;
}
  • Radio Button
- (BOOL)viewController: (UIViewController*)viewController
               onTapUp: (BaseAnnot*)annot
{
    if ([annot isMemberOfClass: PlugPDFRadioButtonField.class]) {
        [[annot document] setRadioButtonFieldWithPage: self.vc.pageIdx
                                                title:((PlugPDFRadioButtonField*)annot).title
                                                 name:((PlugPDFRadioButtonField*)annot).name
                                              checked: YES];
        return YES;
    }
    return NO;
}


Remove Form Field

Following the code snippet, you can remove the form field with the below code.

- (BOOL)viewController: (UIViewController*)viewController
               onTapUp: (BaseAnnot*)annot
{
    if ([annot isMemberOfClass: PlugPDFRadioButtonField.class]) {
        [self.vc removeAnnot: annot];
    }
    return NO;
}


Flatten Form Field

How to flatten PDF form field?

To protect the integrity of PDF files, people often want to flatten their PDF file.

The PlugPDF SDK provides the simplest way to make flatten PDF form field in the PlugPDF SDK.

[self.vc flattenAnnotations];

You can also make a button and add the function in your pdf viewer.



Text Field

In the PlugPDFAnnotEventDelegate, the PlugPDFSDK provides some more delegate methods for the text field.

The below delegate method is called before and after displaying keyboard for the Text Field.

 - (void)keyboardWillShow: (PlugPDFTextField*)textField fieldOffset: (CGFloat)offset Notification: (NSNotification*)notification
{

}

- (void)keyboardWillHide: (PlugPDFTextField*)textField fieldOffset: (CGFloat)offset Notification: (NSNotification*)notification
{

}

Also, you can detect when text field’s values are changed and editing is finished.

- (BOOL)textFieldShouldEndEditing: (PlugPDFTextField*)textField{

}
- (BOOL)textField: (PlugPDFTextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{

}