How to Remove Digital Signature Field from PDF in C#, VB.NET

As a comprehensive PDF component, Spire.PDF supports to sign a PDF digitally, embed certificate in PDF as well as delete signatures in existing PDF documents. In this article, you'll learn how to remove all digital signatures from a PDF with C#, VB.NET.

Test File:

How to Remove Digital Signature Field from PDF in C#, VB.NET

Code Snippet:

Step 1: Create a new PdfDocument object and load the test file.

PdfDocument pdf = new PdfDocument("test.pdf");

Step 2: Get loaded form from PDF.

PdfFormWidget widgets = pdf.Form as PdfFormWidget;

Step 3: Get the list of filed collection, and judge if each filed is a signature filed. If yes, remove the signature field using PdfFieldCollection.RemoveAt(int index) method.

for (int i = 0; i < widgets.FieldsWidget.List.Count; i++)
{
    PdfFieldWidget widget = widgets.FieldsWidget.List[i] as PdfFieldWidget;
    if (widget is PdfSignatureFieldWidget)
    {
        widgets.FieldsWidget.RemoveAt(i);
    }
}

Step 4: Save and launch the result file.

pdf.SaveToFile("result.pdf");
System.Diagnostics.Process.Start("result.pdf");

Result:

How to Remove Digital Signature Field from PDF in C#, VB.NET

Full Code:

[C#]
PdfDocument pdf = new PdfDocument("test.pdf");

PdfFormWidget widgets = pdf.Form as PdfFormWidget;
for (int i = 0; i < widgets.FieldsWidget.List.Count; i++)
{
    PdfFieldWidget widget = widgets.FieldsWidget.List[i] as PdfFieldWidget;
    if (widget is PdfSignatureFieldWidget)
    {
        widgets.FieldsWidget.RemoveAt(i);
    }
}

pdf.SaveToFile("result.pdf");
System.Diagnostics.Process.Start("result.pdf");
[VB.NET]
Dim pdf As New PdfDocument("test.pdf")

Dim widgets As PdfFormWidget = TryCast(pdf.Form, PdfFormWidget)
For i As Integer = 0 To widgets.FieldsWidget.List.Count - 1
	Dim widget As PdfFieldWidget = TryCast(widgets.FieldsWidget.List(i), PdfFieldWidget)
	If TypeOf widget Is PdfSignatureFieldWidget Then

		widgets.FieldsWidget.RemoveAt(i)
	End If
Next

pdf.SaveToFile("result.pdf")
System.Diagnostics.Process.Start("result.pdf")