x509certificate2 Add Digital Signature to PDF Programmatically

x509certificate2 can be used to get important information about an existing certificate (valid dates, issuer, etc.). Using IronPDF, we can digitally sign a PDF using C#, creating a new document or signing an existing PDF file. It takes just a single line of code and we'll walk you through the steps below.


Step 1

1. Get IronPDF

First, install IronPDF to your Visual Studio project. Get it whichever way is easier for you, either from DLL download or on the NuGet website. Access the C# Library in Visual Studio and let's add a signature.

Install-Package IronPdf

How to Tutorial

2. Understanding Digital Signatures

A Digital Signature is like an electronic driver’s license or passport that proves your identity. A digital ID usually contains your name and email address, the name of the organization that issued it, a serial number, and an expiration date. Digital IDs are used for certificate security and digital signatures. This will need to be created with Adobe Acrobat in order for it to work.


3. Digitally Sign a PDF

Now, let's see the steps for creating a x509certificate2 to digitally sign a PDF using C#.

Today, we'll be using IronPDF to save us time and effort in applying the signature, only a single line of code. You can use it free for development to test your work. Then, decide on your project. Will you be creating a new document or signing an existing PDF?

In the below code example, we used a C# form to allow the user to select their desired PDF, which can receive a digital signature with a single click.

We already have a .pfx file (Personal Information Exchange Format), which is used to transfer a certificate with the help of private key.

We use the “SignPdfFile(FileName)” method, and select the file we want to sign.

/**
Digitally Sign a PDF
anchor-digitally-sign-a-pdf
**/
using System.Drawing;
using System.Windows.Forms;
using IronPdf;

namespace digitalsign
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent(); 
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            //select the desired pdf file
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = openFileDialog1.FileName;
            }
        }
        private void button2_Click(object sender, System.EventArgs e)
        {
            //Here we have called an PDFSignature method to digitally sign the Existing PDF
            new PdfSignature("Ironpdf.pfx", "123456").SignPdfFile(textBox1.Text);

            //Used as confirmation
            label3.Text = "Completed !";
            label3.BackColor = Color.LightGreen;
            label3.ForeColor = Color.Black;
        }
    }
}
/**
Digitally Sign a PDF
anchor-digitally-sign-a-pdf
**/
using System.Drawing;
using System.Windows.Forms;
using IronPdf;

namespace digitalsign
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent(); 
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            //select the desired pdf file
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = openFileDialog1.FileName;
            }
        }
        private void button2_Click(object sender, System.EventArgs e)
        {
            //Here we have called an PDFSignature method to digitally sign the Existing PDF
            new PdfSignature("Ironpdf.pfx", "123456").SignPdfFile(textBox1.Text);

            //Used as confirmation
            label3.Text = "Completed !";
            label3.BackColor = Color.LightGreen;
            label3.ForeColor = Color.Black;
        }
    }
}
'''
'''Digitally Sign a PDF
'''anchor-digitally-sign-a-pdf
'''*
Imports System.Drawing
Imports System.Windows.Forms
Imports IronPdf

Namespace digitalsign
	Partial Public Class Form1
		Inherits Form

		Public Sub New()
			InitializeComponent()
		End Sub

		Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			'select the desired pdf file
			If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
				textBox1.Text = openFileDialog1.FileName
			End If
		End Sub
		Private Sub button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			'Here we have called an PDFSignature method to digitally sign the Existing PDF
			Call (New PdfSignature("Ironpdf.pfx", "123456")).SignPdfFile(textBox1.Text)

			'Used as confirmation
			label3.Text = "Completed !"
			label3.BackColor = Color.LightGreen
			label3.ForeColor = Color.Black
		End Sub
	End Class
End Namespace
VB   C#

4. Review Document Signature

As you can see in the below output, first we selected the PDF. As soon as we clicked on the Import Signature button, it successfully digitally signs the document. With IronPDF, it just took a single line of code.


Library Quick Access

API Reference

Read the IronPDF documentation and full list of functions.

API Reference

You can download the software product from this link.