Adding a certified signature field to a PDF in UWP
To add a certification signature field to a PDF document and sign it:
PDFDoc document = new PDFDoc(inputDocumentPath);
Page page1 = document.GetPage(1);
// Create a random text field that we can lock using the field permissions feature.
TextWidget annotation = TextWidget.Create(document, new pdftron.PDF.Rect(50, 550, 350, 600), "asdf_test_field");
page1.AnnotPushBack(annotation);
/* Create new signature form field in the PDFDoc. The name argument is optional;
leaving it empty causes it to be auto-generated. However, you may need the name for later.
Acrobat doesn't show digsigfield in side panel if it's without a widget. Using a
Rect with 0 width and 0 height, or setting the NoPrint/Invisible flags makes it invisible. */
DigitalSignatureField certificationSignatureField = document.CreateDigitalSignatureField(inputCertificateFieldName);
SignatureWidget widgetAnnot = SignatureWidget.Create(document, new pdftron.PDF.Rect(0, 100, 200, 150), certificationSignatureField);
page1.AnnotPushBack(widgetAnnot);
// (OPTIONAL) Add an appearance.
// Widget AP from image
Image image = Image.Create(document.GetSDFDoc(), inputAppearanceImagePath);
widgetAnnot.CreateSignatureAppearance(image);
// End of optional appearance-adding code.
// Add permissions. Lock the random text field.
WriteLine("Adding document permissions.");
certificationSignatureField.SetDocumentPermissions(DigitalSignatureFieldDocumentPermissions.e_annotating_formfilling_signing_allowed);
WriteLine("Adding field permissions.");
string[] fieldsToLock = new string[1];
fieldsToLock[0] = "asdf_test_field";
certificationSignatureField.SetFieldPermissions(DigitalSignatureFieldFieldPermissions.e_include, fieldsToLock);
certificationSignatureField.CertifyOnNextSave(inputPrivateKeyFilePath, inputKeyFilePassword);
///// (OPTIONAL) Add more information to the signature dictionary.
certificationSignatureField.SetLocation("Vancouver, BC");
certificationSignatureField.SetReason("Document certification.");
certificationSignatureField.SetContactInfo("www.apryse.com");
///// End of optional sig info code.
// Save the PDFDoc. Once the method below is called, PDFNetC will also sign the document using the information provided.
await document.SaveAsync(inputOutPath, 0);Digitally sign PDF files Full code sample which demonstrates using the digital signature API to digitally sign and/or certify PDF documents.
About certifying a PDF document
Unlike, approval signatures, there can be only one certification per PDF document. Only the first signature in the PDF document can be used as the certification signature. Certifying a document is like notarizing a document. The process of certifying a document is almost exactly the same as adding approval signatures with the exception of certification signatures requires an entry in the "Perms" dictionary.
About certifying a PDF/A document
If you want to certify a PDF/A document, it is best to convert to PDF/A first, then certify. This is because PDF/A changes the contents of the document, while digital signatures, including certifications, rely on the document's bytes remaining the same so that they can be digested and compared with the embedded cryptographic digital signature.
A DigitalSignatureField can be added before or after PDF/A conversion, since there aren't any requirements in PDF/A upon it.
The PDF/A-2 specification allows adbe.pkcs7.detached and adbe.pkcs7.sha1 certification-type or UR3-type cryptographic digital signatures, with or without secure timestamps, with or without embedded revocation information, which must be signed if present. A single SignerInfo must be present. Attribute certificates must not be used. The PDFNet SDK's signing support is sufficient to meet the requirements of PDF/A-2 compliance if used properly.
There shouldn't be any problem with retaining PDF/A compliance after digitally signing a document, so long as there is no annotation appearance for the digital signature field, or there is an appearance and that appearance conforms to PDF/A, i.e. e.g. sections 6.3.2 and 6.3.3 of the PDF/A-2 specification (ISO-19005-2).
An additional limitation of PDF/A for digital signing is the implementation limit that says that a conforming file shall not contain any string longer than 32767 bytes. Sometimes, signatures with a large amount of data will cause the Contents byte string in the digital signature dictionary to exceed this limit.
The PDF/A-2 specification also mentions the following:
Here is what 6.3.2 and 6.3.3 say about the annotation:
Last updated
Was this helpful?