Saving and storing electronic signatures on Android
PSPDFKit allows you to implement your own mechanism for storing signatures.
If you provide such a mechanism, then signatures may optionally be saved at the same time they’re added to a document. The saving of signatures is based on the signatureSavingStrategy
: This defaults to showing a toggle in the UI that allows the user to choose whether to save, but you can change this option to hide the toggle and instead always save signatures without giving the user the choice.
For signature storage to work, a SignatureStorage
must first be set on your PdfFragment
with PdfFragment#setSignatureStorage
.
If you provide stored signatures to PSPDFKit, then when the user selects a signature form field or the signature tool, the list of stored signatures will be shown instead of the signature creation UI.
SignatureStorage
can be used to create your own solution for storing and retrieving signatures. A signature store can be set on the PdfFragment#setSignatureStorage
to make user-created signatures savable.
By default, no signature store is provided. If you want to use the built-in storage solution that uses the DatabaseSignatureStorage
, you can use a setup like this:
// Make sure saving is enabled in the configuration. val configuration = PdfConfiguration.Builder() .signatureSavingStrategy(SignatureSavingStrategy.SAVE_IF_SELECTED) .build() ... // PDF Activity class: override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // You can create any number of signature storage databases. val storage: SignatureStorage = DatabaseSignatureStorage .withName("MyCoolSignatureDatabase") // Configure your custom storage method in the fragment. pdfFragment.setSignatureStorage(storage) }
// Make sure saving is enabled in the configuration. final PdfConfiguration configuration = new PdfConfiguration.Builder() .signatureSavingStrategy(SignatureSavingStrategy.SAVE_IF_SELECTED) .build(); ... // PDF Activity class: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // You can create any number of signature storage databases. final SignatureStorage storage = DatabaseSignatureStorage .withName("MyCoolSignatureDatabase"); // Configure your custom storage method in the fragment. getPdfFragment().setSignatureStorage(storage); }
However, you can also create your own storage by implementing a class that conforms to the SignatureStorage
protocol. To conform to this protocol, you’ll need to handle adding, removing, and retrieving existing signatures from your custom store. addSignature
will be called whenever the user has created a signature and enabled saving this signature in the signing UI.