Products Technologies Demo Docs Blog Support Company
TX Text Control 34.0 SP1 has been released - Learn more

Sign PDF Documents with an X.509 Certificate on a Hardware Device

TX Text Control can be used to retrieve certificates from a hardware device (such as the Windows certificate store, smart cards and PIV cards, USB tokens). This article shows how to use an X.509 certificate stored on a Windows machine in the Windows certificate store.

Sign PDF Documents with an X.509 Certificate on a Hardware Device

TX Text Control can digitally sign Adobe PDF and PDF/A documents with X.509 certificates. An X.509 certificate is a digital certificate that implements the widely accepted X.509 Public Key Infrastructure (PKI) standard that verifies that a specific public key belongs to a user, computer, or service identity contained in the certificate. The certificate can be assigned in the SaveSettings class when the document is saved.

Document Signing Methods

There are two approaches to signing PDF documents with TX Text Control:

  • Sign the whole document with a digital certificate
  • Sign individual signature fields with a digital certificate(s)

In both approaches, signatures can be created with PFX, DER Cer, or Base64 CER certificate files, loaded from raw data, or selected from the local certificate store.

Windows Certificate Store

The following method opens a dialog box that allows the user to select the desired certificate from the local Windows certificate store. The selected certificate is returned and can be used to sign the document or the signature fields in a PDF document.

The X509Certificate2UI class provides a user interface for selecting and viewing X.509 certificates. The following code uses the SelectFromCollection method to open a certificate selection dialog. All registered certificates, including smart cards, are listed in the dialog.

static X509Certificate2 RetrieveCertificate() {
         
   // get and open certificate store for current user
   X509Store store = new X509Store(StoreLocation.CurrentUser);
   store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);

   // retrieve the certificate using the integrated Windows UI
   X509Certificate2Collection selectedCertificates =
           X509Certificate2UI.SelectFromCollection(
              store.Certificates, 
              "Choose your certificate",
              "Please select a certificate that is used to sign the PDF.",
              X509SelectionFlag.SingleSelection);

   // return the first selected certificate with a private key
   foreach (var certificate in selectedCertificates) {
      if (certificate.HasPrivateKey)
         return certificate;
   }

   return null;
}

Signing the PDF

The CreateEncryptedPDF method takes the selected certificate and a document in the internal TX Text Control format and creates a PDF document signed with the given certificate.

public byte[] CreateEncryptedPDF(byte[] document, X509Certificate2 certificate) {
   byte[] bPDF;

   using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
      tx.Create();
      tx.Load(document, TXTextControl.BinaryStreamType.InternalUnicodeFormat);

      // apply the first selected certificate
      TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings() {
         DigitalSignature = new TXTextControl.DigitalSignature(certificate, null)
      };

      // save the document as PDF
      tx.Save(out bPDF, TXTextControl.BinaryStreamType.AdobePDFA, saveSettings);
   }

   return bPDF;
}

The following code shows how to call this method with the certificate returned from the certificate store.

CreateEncryptedPDF(document, RetrieveCertificate());

The dialog box for selecting the certificate from the local Windows certificate store is shown in the following screenshot.

Windows certificate store

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

ASP.NET

Integrate document processing into your applications to create documents such as PDFs and MS Word documents, including client-side document editing, viewing, and electronic signatures.

ASP.NET Core
Angular
Blazor
JavaScript
React
  • Angular
  • Blazor
  • React
  • JavaScript
  • ASP.NET MVC, ASP.NET Core, and WebForms

Learn more Trial token Download trial

Related Posts

ASP.NETASP.NET Core

AI-Ready Documents in .NET C#: How Structured Content Unlocks Better…

Most organizations use AI on documents that were never designed for machines. PDFs without tags, inconsistent templates, undescribed images, and disorganized reading orders are still common. This…


ASP.NETASP.NET CoreDocument Automation

Why Document Processing Libraries Require a Document Editor

A document processing library alone cannot guarantee reliable and predictable results. Users need a true WYSIWYG document editor to design and adjust templates to appear exactly as they will after…


ASP.NETWindows FormsWPF

TX Text Control 34.0 SP1 is Now Available: What's New in the Latest Version

TX Text Control 34.0 Service Pack 1 is now available, offering important updates and bug fixes for all platforms. If you use TX Text Control in your document processing applications, this service…


ASP.NETASP.NET CoreConference

Scaling TX Text Control Document Editor Applications

Learn how to scale TX Text Control Document Editor applications effectively for enhanced performance and user experience. A practical guide for high performance architectures.


ASP.NETASP.NET CoreConference

Text Control at DDC 2025: Bringing Next-Generation Document Technology to…

This week, we exhibited at the DDC 2025 conference in Cologne. It's a small but important event for the .NET community in the German-speaking world. For us at Text Control, it was an opportunity…

Summarize this blog post with:

Share on this blog post on: