How to retrieve all signatures in a signed document?

Q: How to retrieve all signatures in a signed document?

Finding All Digital Signatures

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

Copy
1
2
3
4
5
6
7
8
9
10
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 info.
        ...
    }
}
Copy
1
2
3
4
5
6
7
8
9
10
11
@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 info.
        ...
    }
}

See here 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 contain an ink signature you can use the following snippet:

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// 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.
    })
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 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.
    });