How to Retrieve All Signatures in a Signed Document

This guide outlines how to retrieve signatures in a signed document.

Finding All Digital Signatures

If you want to retrieve all the digital signatures in document, you can retrieve all the signed form fields in the following way:

override fun onDocumentLoaded(document: PdfDocument) {
    // This will return all signed signature form fields in the document.
    val signatureFormFields = document.documentSignatureInfo.signatureFormFields

    for (signatureFormField in signatureFormFields) {
        val signatureInfo = signatureFormField.signatureInfo
        // Process the signature information.
        ...
    }
}
@Override
public void onDocumentLoaded(@NonNull PdfDocument document) {
    // This will return all signed signature form fields in the document.
    List<SignatureFormField> signatureFormFields = document.getDocumentSignatureInfo().getSignatureFormFields();

    for (SignatureFormField signatureFormField : signatureFormFields) {
        DigitalSignatureInfo signatureInfo = signatureFormField.getSignatureInfo();
        // Process the signature information.
        ...
    }
}

See here for information on how to create digital signatures.

Finding All Form Fields with Overlapping Ink Signatures

If you want to find signature form fields that aren’t digitally signed but that contain an ink signature, use the following snippet:

// This will return all form elements in the document.
document.formProvider.formElementsAsync
    // Convert them to an observable stream.
    .flatMapObservable {
        Observable.fromIterable(it)
    }
    // Filter all signature form elements and cast them.
    .filter { formElement -> formElement is SignatureFormElement }
    .cast(SignatureFormElement::class.java)
    // This will create a list of all form elements with a signature on them.
    .flatMapMaybe({ signatureFormElement -> signatureFormElement.getOverlappingInkSignatureAsync().map({ inkAnnotation -> signatureFormElement }) })
    .toList()
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe({ formElements ->
        // A list of all form elements with ink signatures on them, or an empty list if there are none.
    }, { throwable ->
        // An error was thrown.
    })
// This will return all form elements in the document.
document.getFormProvider().getFormElementsAsync()
    // Convert them to an observable stream.
    .flatMapObservable(Observable::fromIterable)
    // Filter all signature form elements and cast them.
    .filter(formElement -> formElement instanceof SignatureFormElement)
    .cast(SignatureFormElement.class)
    // This will create a list of all form elements with a signature on them.
    .flatMapMaybe(signatureFormElement -> signatureFormElement.getOverlappingInkSignatureAsync().map(inkAnnotation -> signatureFormElement))
    .toList()
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(formElements -> {
        // A list of all form elements with ink signatures on them, or an empty list if there are none.
    }, throwable -> {
        // An error was thrown.
    });