Products Technologies Demo Docs Blog Support Company

Digitally Sign PDF/A Documents with Self-Signed Certificates

TX Text Control can be used to digitally sign Adobe PDF and PDF/A documents with X.509 certificates. This article shows how to create a self-signed certificate and how to sign documents with it.

Digitally Sign PDF/A Documents with Self-Signed Certificates

TX Text Control can be used to digitally sign Adobe PDF and PDF/A documents with X.509 certificates. The certificate can be assigned in the SaveSettings class when saving document.

Creating Adobe PDFs

Consider the following Web API code that accepts a document in the internal TX Text Control format as a Base64 encoded string and returns a signed Adobe PDF document as a Base64 encoded string which is a typical practice for document APIs.

[HttpPost]
public string ExportPDF(string document)
{
    byte[] bPDF;

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

        X509Certificate2 cert = new X509Certificate2
            (Server.MapPath("~/App_Data/textcontrolself.pfx"),
             "yourpassword");

        TXTextControl.SaveSettings saveSettings = new TXTextControl.SaveSettings()
        {
            DigitalSignature = new TXTextControl.DigitalSignature(cert, null)
        };

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

    // return as Base64 encoded string
    return Convert.ToBase64String(bPDF);
}

In this case, a X509Certificate2 is created from the certificate file textcontrolself.pfx and the private key password.

After the document has been created and is opened in Acrobat Reader, the valid signatures are shown in the Signatures sidebar:

Certificate

Creating the Self-Signed Certificate

In the next steps, a self-signed certificate is created using Windows PowerShell.

  • Use the New-SelfSignedCertificate PowerShell cmdlet to create a self signed certificate. Open a PowerShell and type in the following command:

    New-SelfSignedCertificate -Type Custom -Subject "CN=Text Control, O=Text Control, C=US" -KeyUsage DigitalSignature -FriendlyName "TextControlSelf" -CertStoreLocation "Cert:\CurrentUser\My" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}")

    After running this command, the certificate is added to the certificate store (specified in the "-CertStoreLocation" parameter). The output of the command shows the certificate's thumbprint.

    PSParentPath: Microsoft.PowerShell.Security\Certificate::CurrentUser\My
    
    Thumbprint                                Subject
    ----------                                -------
    6BA35B742656FB2EC48B09116ABAE5123082F116  CN=Text Control, O=Text Control, C=US
  • Copy this thumbprint and insert it into the following command:

    $password = ConvertTo-SecureString -String yourpassword -Force -AsPlainText 
    Export-PfxCertificate -cert "Cert:\CurrentUser\My\6BA35B742656FB2EC48B09116ABAE5123082F116" -FilePath textcontrolself.pfx -Password $password
  • The file textcontrolself.pfx is created in the same folder. Copy this to your application's folder from where you want to load the certificate (App_Data in our Web API sample above).

In real-world applications, the private key can be also accessed from the certificate store. In this case, make sure that the current user (IIS_IUSRS) has full access.

Certificate

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Also See

This post references the following in the documentation:

  • TXTextControl.DigitalSignature Class
  • TXTextControl.SaveSettings.DigitalSignature Property

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 CoreCertificate

How to Sign PDF Documents with PFX Certificates in .NET C# on Linux

This article shows how to sign PDF documents with PFX certificates in .NET C# on Linux. The sample code uses the TX Text Control .NET Server component to create a PDF document and digitally sign…


ASP.NETASP.NET CoreDocument Conversion

Convert DOCX to PDF, PDF/A and PDF/UA in C# Using TX Text Control

Learn how to convert Word DOCX documents to PDF in C# using TX Text Control .NET Server. This tutorial covers file-based and in-memory conversion, PDF/A export, document metadata, font deployment,…


ASP.NETASP.NET CoreMCP

Reliable Document AI in .NET: LLM Tool Calling vs. LLM-Generated Files

Reliable document AI needs a deterministic engine. With LLM tool calling, the LLM decides what the document should contain, and TX Text Control generates the file.


ASP.NETASP.NET CoreDocument Generation

Building a Production-Ready PDF Generation Pipeline in C# with ASP.NET Core

Learn how to build a reliable PDF generation pipeline with TX Text Control and ASP.NET Core. Use durable background jobs, idempotency, renewable leases, PDF validation, and private artifact…


ASP.NETASP.NET CoreDocument Viewer

Native PDF Annotation Support Is Coming to the TX Text Control Document Viewer

The next version of the TX Text Control Document Viewer will introduce an important enhancement to PDF workflows: native support for PDF-compatible annotations. Users will be able to add…

Share this blog post on:

​​​