Sign a PDF Document in C# and VB .NET
Published: 2022-01-24 06:17:50

---
canonical_url: https://ironpdf.com/docs/questions/signing/
---

Developers commonly ask how they can programmatically add a signature to a PDF document using Iron PDF and C# or VB.NET

Commonly this means different things to different developers:

1. To add a graphical handwritten signature image to an existing Pdf from an image file
2. To cryptographically sign a PDF document to ensure it can not been tampered with
3. To cryptographically sign a PDF document h AND add a human handwritten signature

## 1 - Stamping a Handwritten Signature onto a PDF Page

This method will stamp a signature PNG onto an existing PDF page. It could be used for a company stamp or a hand written signature. Opacity is Supported.

The **HtmlStamp** class supports stamping of any HTML content, which may be resized and positioned on the page using: _Width_, _Height_, _Top_, _Bottom_, _Left_ and _Right _in Pixels.

**C#:**
```
//PDFs can be edited or amended by stamping new HTML content into the foreground or background.
using IronPdf;
using IronPdf.Editing;
// open an existing PDF document or create a new one
PdfDocument Pdf = PdfDocument.FromFile(@"C:\Path\To\UnSigned.pdf");
var SignatureStamp = new HtmlStamp() { Html = "<img src='signature.png' />", Width = 150, Height = 50, Bottom = 300, Left=85, ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent };
Pdf.StampHTML(SignatureStamp,1);
Pdf.SaveAs(@"C:\Path\To\Signed.pdf");
```

**VB:**
```
'PDFs can be edited or amended by stamping new HTML content into the foreground or background.
Imports IronPdf
Imports IronPdf.Editing
' open an existing PDF document or create a new one
Private Pdf As PdfDocument = PdfDocument.FromFile("C:\Path\To\UnSigned.pdf")
Private SignatureStamp = New HtmlStamp() With {
	.Html = "<img src='signature.png' />",
	.Width = 150,
	.Height = 50,
	.Bottom = 300,
	.Left=85,
	.ZIndex = HtmlStamp.StampLayer.OnTopOfExistingPDFContent
}
Pdf.StampHTML(SignatureStamp,1)
Pdf.SaveAs("C:\Path\To\Signed.pdf")
```

## 2 - Cryptographically signing a PDF document

The following method cryptographically signs a PDF using a .pfx and .p12 X509Certificate2 digital certificate which can be created easily from with Adobe Reader.

Read: [https://helpx.adobe.com/acrobat/using/digital-ids.html](https://helpx.adobe.com/acrobat/using/digital-ids.html)

**C#:**
```
using IronPdf;
// 123456 below represents the signature password
new IronPdf.PdfSignature("CertificateFile.p12", "123456").SignPdfFile("UnSecure.pdf");
```

**VB:**
```
Imports IronPdf
' 123456 below represents the signature password
Call (New IronPdf.PdfSignature("CertificateFile.p12", "123456")).SignPdfFile("UnSecure.pdf")
```

## 3 - Cryptographically signing a PDF document and do so with a Hand Written signature

This more advanced example allows the .pfx / .p12 X509Certificate2 digital id signing method to be combined with a scan of a handwritten signature.

**C#:**
```
var Signature = new IronPdf.PdfSignature("Iron.pfx", "123456");
// Step 3. Optional signing options and a handwritten Signature graphic
Signature.SigningContact = "support@ironsoftware.com";
Signature.SigningLocation = "Chicago, USA";
Signature.SigningReason = "To show how to sign a PDF";
Signature.LoadSignatureImageFromFile("handwriting.png");
Signature.SignPdfFile("UnSecure.pdf");
```

**VB:**
```
Dim Signature = New IronPdf.PdfSignature("Iron.pfx", "123456")
' Step 3. Optional signing options and a handwritten Signature graphic
Signature.SigningContact = "support@ironsoftware.com"
Signature.SigningLocation = "Chicago, USA"
Signature.SigningReason = "To show how to sign a PDF"
Signature.LoadSignatureImageFromFile("handwriting.png")
Signature.SignPdfFile("UnSecure.pdf")
```

Cryptographic PDF signing may also be achieved during the PDF creation and rendering ( **HTML to PDF** ) process

**C#:**
```
// Step 1. Create a PDF
IronPdf.ChromePdfRenderer Renderer = new IronPdf.ChromePdfRenderer();
PdfDocument doc = Renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>");
// Step 2. Create a Signature.
// You may create a .pfx or .p12 PDF signing certificate using Adobe Acrobat Reader.
// Read: https://helpx.adobe.com/acrobat/using/digital-ids.html
var Signature = new IronPdf.PdfSignature("Iron.pfx", "123456");
// Step 3. Optional signing options and a handwritten Signature graphic
Signature.SigningContact = "support@ironsoftware.com";
Signature.SigningLocation = "Chicago, USA";
Signature.SigningReason = "To show how to sign a PDF";
Signature.LoadSignatureImageFromFile("handwriting.png");
//Step 4. Sign the PDF with the PdfSignature. Multiple signing certificates may be used
doc.SignPdfWithDigitalSignature(Signature);
//Step 4. The PDF is not signed until saved to file, steam or byte array.
doc.SaveAs("signed.pdf");
```

**VB:**
```
' Step 1. Create a PDF
Dim Renderer As New IronPdf.ChromePdfRenderer()
Dim doc As PdfDocument = Renderer.RenderHtmlAsPdf("<h1>Testing 2048 bit digital security</h1>")
' Step 2. Create a Signature.
' You may create a .pfx or .p12 PDF signing certificate using Adobe Acrobat Reader.
' Read: https://helpx.adobe.com/acrobat/using/digital-ids.html
Dim Signature = New IronPdf.PdfSignature("Iron.pfx", "123456")
' Step 3. Optional signing options and a handwritten Signature graphic
Signature.SigningContact = "support@ironsoftware.com"
Signature.SigningLocation = "Chicago, USA"
Signature.SigningReason = "To show how to sign a PDF"
Signature.LoadSignatureImageFromFile("handwriting.png")
'Step 4. Sign the PDF with the PdfSignature. Multiple signing certificates may be used
doc.SignPdfWithDigitalSignature(Signature)
'Step 4. The PDF is not signed until saved to file, steam or byte array.
doc.SaveAs("signed.pdf")
```