Retrieve Digital Signature Information from PDFs Using LEADTOOLS

Posted on 2020-02-07 Nick Villalobos

Digital signatures are one of the most advanced and secure type of an electronic signature. These signatures provide the highest level assurance and are used to comply with legal and regulatory requirements. Digital signatures use a certificate-based digital ID to authenticate the signer's identity and bind each signature to the document using encryption. With the LEADTOOLS SDK, developers can use LEADTOOLS PDF libraries to retrieve information on these digital signatures. The .NET and Java PDFSignature Class contains properties of a PDF digital signature.

This is perfect for those in the e-commerce industry, or anyone who receives legal PDF documents with digital signatures. You can check the validity of these signatures, get the certificate information, get the location on the page, and more. All this can be accomplished in just a couple lines of code.

Before you get started, you must download LEAD's OpenSSL-Binaries. The zip file contains the 32/64-bit versions of the latest OpenSSL 1.0.2 and 1.1.0 libraries, compiled and digitally signed by LEAD Technologies, Inc. These need to be added to your project's output directory.


Code it!

using (PDFDocument document = new PDFDocument(sourceFileName))
{
    // Parse the signatures for all pages 
    PDFParsePagesOptions options = PDFParsePagesOptions.Signatures;
    document.ParsePages(options, 1, -1);

    foreach (PDFDocumentPage page in document.Pages)
    {
        // Check PDF for signatures
        if (page.Signatures != null && page.Signatures.Count > 0)
        {
            // Gets the status of digital signature support in the LEADTOOLS PDF toolkit.
            RasterExceptionCode status = PDFDocument.GetDigitalSignatureSupportStatus();
            if (status == RasterExceptionCode.Success)
            {
            	// Get info of PDF Signature
                foreach (var pdfSignature in page.Signatures)
                {
                    Console.WriteLine($"Bounds of signature: {pdfSignature.Bounds}");                                                                
                    Console.WriteLine($"Number of bits of the signature's public key: {pdfSignature.PublicKeyBits}");                                
                    Console.WriteLine($"Page number: {pdfSignature.PageNumber}");
                    Console.WriteLine($"Can signature be validated: {pdfSignature.CanValidate}");
                    Console.WriteLine($"Valid from: {pdfSignature.ValidFrom}");
                    Console.WriteLine($"Valid to: {pdfSignature.ValidTo}");
                    Console.WriteLine($"Signature version: {pdfSignature.Version}");
                    
                    Console.WriteLine($"Certificate Info:");

                    foreach (var info in pdfSignature.CertificateInfo)
                    {
                        Console.WriteLine($"\t{info}");
                    }

                    Console.WriteLine();
                }
            }
        }
    }
}

Try it!

To test this for yourself, you can download my .NET console project. Make sure to get the latest LEADTOOLS SDK code for free straight from our site if you have not already. This trial is good for 60 days and comes with unlimited chat and email support.

Support

Need help getting this sample up and going? Contact our support team for free technical support! For pricing or licensing questions, you can contact our sales team (sales@leadtools.com) or call us at 704-332-5532.

LEADTOOLS Blog

LEADTOOLS Powered by Apryse,the Market Leading PDF SDK,All Rights Reserved