public abstract class

Signer

extends Object
java.lang.Object
   ↳ com.pspdfkit.signatures.signers.Signer
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Represents a signer (person and algorithm) used to digitally sign a document. Implementations of this class are, for example, MemorySigner and Pkcs12Signer. Subclasses need to implement prepareSigningParameters(OnSigningParametersReadyCallback) which will be called by the signer whenever a digital signing operation is initiated.

Summary

Nested Classes
interface Signer.OnSigningParametersReadyCallback Callback passed to prepareSigningParameters(OnSigningParametersReadyCallback) whenever a signing process was initiated and the signer needs to load its SignatureProvider
Protected Constructors
Signer(String displayName)
Create the Signer.
Public Methods
final Completable embedSignatureInFormFieldAsync(SignatureFormField formField, SignatureContents contents, OutputStream destination)
Embeds signature contents in a signature form field.
final String getDisplayName()
Gets the display name of this signer for use in the UI.
final Completable prepareFormFieldForSigningAsync(SignerOptions signerOptions)
Builds a document where form field is prepared with a custom appearance and filled with SignatureContents.
final void signFormField(SignerOptions signerOptions)
Signs a SignatureFormField form element (and with that, the document).
Completable signFormFieldAsync(SignerOptions signerOptions)
Signs a SignatureFormField form element (and with that, the document) asynchronously on a background thread.
Protected Methods
void prepareSigningParameters(Signer.OnSigningParametersReadyCallback callback)
Called by Signer whenever the implementation should prepare required signing parameters.
[Expand]
Inherited Methods
From class java.lang.Object

Protected Constructors

protected Signer (String displayName)

Create the Signer.

Parameters
displayName The human readable name of this signer.

Public Methods

public final Completable embedSignatureInFormFieldAsync (SignatureFormField formField, SignatureContents contents, OutputStream destination)

Embeds signature contents in a signature form field. It assumes that the document that contains signatureFormField has been prepared for digital signing by calling prepareFormFieldForSigningAsync(SignerOptions) before.

Note that this API does not allow any more arguments (as defined in SignerOptions, because if we want the signature to remain valid we can’t touch the document any more than changing the signature contents set via prepareFormFieldForSigningAsync(SignerOptions) with signature contents. No appearance, no biometric properties, etc.

Parameters
formField The signature form field to sign.
contents Signature contents that will be embedded in the document.
destination The destination to output the signed document.
Returns
  • Completable emitting complete event when the signing process finishes or failure if it fails.

public final String getDisplayName ()

Gets the display name of this signer for use in the UI. This is usually the name of the person that is signing the document.

Returns
  • A string representing the name of this signer.

public final Completable prepareFormFieldForSigningAsync (SignerOptions signerOptions)

Builds a document where form field is prepared with a custom appearance and filled with SignatureContents.

Typically, you will want to pass an instance of a BlankSignatureContents as signature contents to simply fill the signature contents with zeros.

Note that the document generated by this method has two important properties:
  • First, it’s not a valid digitally signed document yet, so it may show errors if you try to validate it with PSPDFKit or any other third-party tool.
  • Second, this document must not be modified in any way, in order to prevent corrupting the digital signature that will be embedded in the final document.

Parameters
signerOptions Signer options to use, expects signatureContents to be set.
Returns
  • Completable emitting complete event when preparing form field for signing finishes or failure if it fails.

public final void signFormField (SignerOptions signerOptions)

Signs a SignatureFormField form element (and with that, the document).

NOTE: Signing a document requires reading it in full and will take a lot of time. Do not attempt to invoke that on main thread. Prefer to use signFormFieldAsync(SignerOptions) if possible.

Parameters
signerOptions The SignerOptions to use for signing this document.

public Completable signFormFieldAsync (SignerOptions signerOptions)

Signs a SignatureFormField form element (and with that, the document) asynchronously on a background thread.

Parameters
signerOptions The SignerOptions to use for signing this document.
Returns

Protected Methods

protected void prepareSigningParameters (Signer.OnSigningParametersReadyCallback callback)

Called by Signer whenever the implementation should prepare required signing parameters. This is an asynchronous operation, which is completed by the implementation handing over the signing parameters using the given Signer.OnSigningParametersReadyCallback. Signing parameters include:

  • A SignatureProvider that implements the actual data signing logic (i.e. signing and hashing PDF data).
  • The X509Certificate that is embedded to the PDF document while signing.

Parameters
callback An Signer.OnSigningParametersReadyCallback that should be called by the implementation to hand over all required signing parameters.