Articles in this section
Category / Section

How to digitally sign a PDF document with PAdES Level B-LTA

2 mins read

The Syncfusion Essential PDF is a feature-rich and high-performance .NET PDF library that is used to create, read, and edit the PDF documents. This article provides step-by-step instructions on how to digitally sign a PDF document using the PAdES (PDF Advanced Electronic Signature) standard at Level B-LTA. It covers the prerequisites, required tools, and procedures to ensure long-term validation (LTV) and compliance with advanced digital signature standards. Suitable for users who need legally binding and verifiable PDF signatures with timestamping and archival support.

Steps to digitally sign a PDF document with PAdES level B-LTA using C# programmatically

  1. Create a new console application project.
    Console App.png
  2. Install the Syncfusion.Pdf.Net.Core NuGet package as a reference to your console application from Nuget.org.
    NuGet Package.png
  3. Include the following namespaces in the Program.cs file.

C#

using Syncfusion.Pdf.Parsing;
using Syncfusion.Pdf.Security;
using Syncfusion.Pdf;
  1. Use the following code sample in Program.cs to sign a PDF document with LTA by utilizing the TimeStampServer property and EnableLtv property in PdfSignature class.
    C#
// Load the existing PDF document from the specified file path
using (FileStream documentStream1 = new FileStream(@"Data/Input.pdf", FileMode.Open, FileAccess.Read))
{
   PdfLoadedDocument loadedDocument = new PdfLoadedDocument(documentStream1);

   // Load the digital certificate (.pfx) with its password
   using (FileStream documentStream2 = new FileStream(@"Data/DigitalSignatureTest.pfx", FileMode.Open, FileAccess.Read))
   {
       PdfCertificate certificate = new PdfCertificate(documentStream2, "DigitalPass123");

       // Create a digital signature for the PDF document using the loaded certificate
       PdfSignature signature = new PdfSignature(loadedDocument, loadedDocument.Pages[0], certificate, "DigitalSignature");

       // Set cryptographic standard (e.g., CADES for CMS-based signatures)
       signature.Settings.CryptographicStandard = CryptographicStandard.CADES;

       // Set the hashing algorithm for the digital signature
       signature.Settings.DigestAlgorithm = DigestAlgorithm.SHA256;

       // Set the TimeStamp Server for adding a timestamp to the signature
       signature.TimeStampServer = new TimeStampServer(new Uri("http://time.certum.pl"));

       // Enable Long-Term Validation (LTV) for the signature, ensuring it remains valid over time
       signature.EnableLtv = true;

       // Save the PDF document (with the signature) to a memory stream
       using (MemoryStream stream = new MemoryStream())
       {
           loadedDocument.Save(stream);

           // Close the loaded PDF document to release the resources
           loadedDocument.Close(true);

           // Re-load the document from the memory stream to add timestamp signature (LTV)
           using (PdfLoadedDocument ltDocument = new PdfLoadedDocument(stream))
           {
               // Access the first page of the document to apply additional signatures (e.g., timestamp)
               PdfLoadedPage lpage = ltDocument.Pages[0] as PdfLoadedPage;

               // Create a timestamp signature on the loaded document page
               PdfSignature timeStamp = new PdfSignature(lpage, "timestamp");

               // Set the TimeStamp Server for the timestamp signature
               timeStamp.TimeStampServer = new TimeStampServer(new Uri("http://time.certum.pl"));

               // Save the document with the timestamp signature to another memory stream
               using (MemoryStream stream1 = new MemoryStream())
               {
                   ltDocument.Save(stream1);

                   // Create and write the final PDF document to the output file
                   using (FileStream outputFileStream = new FileStream(@"Output/Output.pdf", FileMode.Create, FileAccess.ReadWrite))
                   {
                       // Save the updated PDF document (with both digital signature and timestamp) to the output file
                       ltDocument.Save(outputFileStream);
                   }

                   // Close the document to release resources
                   ltDocument.Close(true);
               }
           }
       }
   }
}

A complete working sample can be downloaded from GitHub.
By executing the program, you will get the PDF document as follows.

Output.png

Take a moment to peruse the documentation to learn how to add digital signature in a PDF document.

Conclusion
I hope you enjoyed learning on how to digitally sign a PDF document with PAdES Level B-LTA.

You can refer to our ASP.NET Core PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our ASP.NET Core PDF example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied