X509certificate2 Add Digital Signature to PDF Programmatically
Published: 2022-01-25 05:03:40

---
canonical_url: https://ironpdf.com/docs/questions/add-digital-signature-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.

**C#:**
```
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;
		}
	}
}
```

**VB:**
```
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
```

---
**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](https://ironpdf.com/packages/IronPdf.Package.For.Add.Digi.Signature.zip) or on the [NuGet website](https://www.nuget.org/packages/IronPdf). Access the C# Library in Visual Studio and let's add a signature.

`PM > Install-Package IronPdf`

---

## 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](https://helpx.adobe.com/sign/using/digital-signatures.html). 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 an 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.

**C#:**
```
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;
        }
    }
}
```

**VB:**
```
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
```

---

## 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.

![digital signature](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2lq733vbsjdr4ksspb2m.png)

![digital sign2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tvgfkrx0x472p236mqrj.png)

---