Add Signature Fields to PDF Forms on iOS

Programmatically creating form fields can be useful when a PDF document needs to be electronically signed or digitally signed but doesn’t contain a signature field.

💡 Tip: A document can still be digitally signed even when it doesn’t have a signature form element.

A form field is a model representation of a visual form in a document. To be able to create a signature form field, you have to first create a SignatureFormElement (a type of widget annotation). This works the same as adding any other annotation, as can be seen in our guide on programmatically creating annotations. For more information on the difference between a form field and a form element, please see our guide on forms.

When the form element has been added to the document on the correct page, you can call insertedSignatureField(withFullyQualifiedName:documentProvider:formElement:) on SignatureFormField. Note that this can fail, and you’ll need to check that the return value isn’t nil:

// Create a new signature form element.
let signatureFormElement = SignatureFormElement()
// Position it in the document.
signatureFormElement.boundingBox = CGRect(x: 100, y: 100, width: 100, height: 20)
// Add it to the third page.
signatureFormElement.pageIndex = 2

// Insert a form field for the form element.
let signatureFormField = try! SignatureFormField.insertedSignatureField(withFullyQualifiedName: "Digital Signature", documentProvider: documentProvider, formElement: signatureFormElement)
// Create a new signature form element.
PSPDFSignatureFormElement *signatureFormElement = [[PSPDFSignatureFormElement alloc] init];
// Position it in the document.
signatureFormElement.boundingBox = CGRectMake(100.f, 100.f, 100.f, 20.f);
// Add it to the third page.
signatureFormElement.pageIndex = 2;

// Insert a form field for the form element.
NSError *error;
PSPDFSignatureFormField *signatureFormField = [PSPDFSignatureFormField insertedSignatureFieldWithFullyQualifiedName:@"Digital Signature" documentProvider:documentProvider formElement:signatureFormElement error:&error];
if (!signatureFormField) {
    // Handle error.
}