Using Electronic Signatures and Digital Signatures Together

Digital signatures are always created by adding a new invisible signature form field to a document. For adding a visual representation of the signature, a common workflow is to first let the user create an electronic signature, and then, once it’s finished, to create the cryptographic digital signature.

For doing this, you can use the Document.AnnotationsCreated event to identify when electronic signatures are created:

PDFView.Document.AnnotationsCreated += (document, annotations) =>
{
	if (annotations.Select(annotation => annotation is Ink).Count() > 2)
	{
		EnableDigitalSigningButton();
	}
};

Then, in a separate workflow, digitally sign the document via code:

private async void DigitalSigningButtonClicked()
{
	var certificate = await GetAssetAsTextAsync("certificate.pem");
	var privateKey = await GetAssetAsTextAsync("private-key.pem");

	// Sign the document. SHA256 or greater is recommended.
	await PDFView.Document.SignAndSaveAsync(HashAlgorithm.Sha256, certificate, privateKey, new SignatureMetadata
	{
		SignerName = "James Swift",
		SignatureReason = "Example Signature",
		SignatureLocation = "Vienna, Austria"
	});
}

To make sure the signature was successful, you can use the ViewState.ShowSignatureValidationStatusMode property. This way, the user is promptly notified of the result.

Our example here isn’t extensive, but it should be able to guide you through the basics so that you can adapt it to more complex use cases. For more information specific to Digital Signatures, including details on two-step signing and validation status, please refer to our Digital Signatures on PSPDFKit for Windows guide.