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

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

Bjoern Meyer

Bjoern Meyer

Updated 11/19/2025

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 it with a PFX certificate.

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

Signing PDFs is critical to ensuring the authenticity, integrity, and non-repudiation of digital documents. A digital signature verifies that a document was created by a trusted entity and has not been altered since it was signed. This is especially important for contracts, invoices, legal agreements, and government documents where authenticity and compliance are mandatory.

PDF digital signing uses Public Key Infrastructure (PKI) to ensure authenticity and prevent tampering. A cryptographic hash of the document is created and encrypted with the signer's private key to form the digital signature. This signature and the signer's certificate are embedded in the PDF. When opened, the PDF reader decrypts the hash with the signer's public key and compares it to a newly generated hash. If they match, the document is verified as unchanged; if not, the signature is flagged as invalid, ensuring document integrity and trust. Security features are essential factors when choosing a PDF library. Use this developer guide for choosing the right C# PDF generation library.

Starting with version 33.0, TX Text Control .NET Server is able to sign PDF documents with certificates such as PFX files on Windows and Linux. This article shows how to create a PFX file on Linux using OpenSSL and how to use this certificate with TX Text Control to sign generated PDF documents.

Prerequisites

You need to download and install the trial version of TX Text Control .NET Server to host the Document Editor backend:

Creating the Application

Make sure that you downloaded the latest version of Visual Studio 2022 that comes with the .NET 8 SDK.

  1. In Visual Studio 2022, create a new project by choosing Create a new project.

  2. Select Console App as the project template and confirm with Next.

  3. Enter a project name and choose a location to save the project. Confirm with Next.

  4. Choose .NET 8.0 (Long Term Support) as the Framework.

  5. Enable the Enable container support checkbox and choose Linux as the Container OS.

  6. Choose Dockerfile for the Container build type option and confirm with Create.

    Creating the .NET 8 project

Adding the NuGet Packages

  1. In the Solution Explorer, select your created project and choose Manage NuGet Packages... from the Project main menu. Select Text Control Offline Packages as the Package source.

    Install the following package:

    • TXTextControl.TextControl.Core.SDK

    ASP.NET Core Web Application

Enable WSL (Windows Subsystem for Linux)

We will use the local WSL installation to generate the certificate. In case you haven't enabled WSL yet, follow these steps:

Enable WSL (Windows Subsystem for Linux)

  1. Open PowerShell as an administrator.

  2. Run the following command:

    wsl --install

    This installs the default Linux distribution (usually Ubuntu) and enables necessary features.

  3. After the installation, restart your computer.

Set WSL 2 as the Default Version

To set WSL 2 as the default version, follow these steps:

  1. Open PowerShell as an administrator.

  2. Run the following command:

    wsl --set-default-version 2
  3. If you haven't installed a Linux distribution yet, you can do so via:

    wsl --install -d Ubuntu

Generate a Self-Signed Certificate with OpenSSL

OpenSSL is a powerful cryptographic toolkit that can be used to generate self-signed certificates.

  1. In Visual Studio, choose View > Terminal from the main menu to open the Terminal.
  2. In the new Terminal window, click the drop-down arrow next to the shell selection and select Developer PowerShell from the list.
  3. Type in the following command to start WSL:

    wsl
  4. Change the current directory to the application folder.

    PowerShell

  1. Now, we can create a self-signed certificate using OpenSSL. The following command will generate a new private key and a Certificate Signing Request (CSR) file:

    openssl req -new -newkey rsa:2048 -nodes -keyout my_private.key -out my_request.csr
  2. After you run this command, you are prompted for information such as the country, state, city, organization, and e-mail address. This information is used to generate the certificate. The private key is stored in the file my_private.key and the CSR in my_request.csr.

  3. Run the following command to sign the CSR and generate the certificate:

    openssl x509 -req -days 365 -in my_request.csr -signkey my_private.key -out my_certificate.crt
  4. This command converts the certificate and private key into a .pfx file:

    openssl pkcs12 -export -out my_certificate.pfx -inkey my_private.key -in my_certificate.crt

You have now created a self-signed certificate in the file my_certificate.pfx.

Created PFX on Linux

Sign a PDF Document with TX Text Control

Now that we have created a PFX file, we can use this certificate to sign a PDF document with TX Text Control.

  1. Open the Program.cs file in Visual Studio and replace the content with the following code:

  2. In the Solution Explorer, right-click the generated PFX file and select Properties. Set the Copy to Output Directory property to Copy if newer.

  3. Run the application by pressing F5. The application creates a PDF document and signs it with the generated certificate.

Open the signed document in a PDF viewer. The signed document displays the signature and certificate details:

Signed PDF Document

Conclusion

Using TX Text Control .NET Server, you can sign PDF documents with certificates such as PFX files on Windows and Linux. This article shows how to create a PFX file on Linux using OpenSSL and how to use this certificate with TX Text Control to sign generated PDF documents.

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 CoreCertificate

How to Sign Signature Fields with Custom Signer Information and Time Stamps…

This article shows how to sign signature fields in a PDF document with custom signer information and timestamps using the TX Text Control .NET Server component in ASP.NET Core C#. The signature is…


ASP.NETASP.NET CoreMIME

Why Defining MIME Types for PDF/A Attachments Is Essential

The PDF/A standard was created to ensure the long-term reliable archiving of digital documents. An important aspect of the standard involves properly handling embedded files and attachments within…


ASP.NETASP.NET CorePDF

Validate Digital Signatures and the Integrity of PDF Documents in C# .NET

Learn how to validate digital signatures and the integrity of PDF documents using the PDF Validation component from TX Text Control in C# .NET. Ensure the authenticity and compliance of your…


ASP.NETASP.NET CorePDF

Validate PDF/UA Documents and Verify Electronic Signatures in C# .NET

The new TXTextControl.PDF.Validation NuGet package enables you to validate PDF/UA documents and verify digital signatures directly in your code without relying on third-party tools or external…


ASP.NETASP.NET CoreC#

How To Choose the Right C# PDF Generation Library: Developer Checklist

To make your choice easy, this guide provides a systematic evaluation framework for two library categories: basic and enterprise PDF libraries. It covers matching features to use cases, evaluating…

Summarize this blog post with:

Share on this blog post on: