How to Extract Image from Signature in PDF

Spire.PDF allows extracting images from signatures using ExtractSignatureAsImages method in PdfFormWidget class. This article demonstrates how we can use Spire.PDF to implement this feature.

Code Snippet:

Step 1: Instantiate an object of PdfDocument class and load the PDF document.

PdfDocument document = new PdfDocument("sample.pdf");

Step 2: Get the existing forms of the document.

PdfFormWidget form = document.Form as PdfFormWidget;

Step 3: Extract images from signatures in the existing forms and put them into an Image Array.

Image[] images = form.ExtractSignatureAsImages();

Step 4: Save the images to disk.

int i = 0;
for (int j = 0; j < images.Length; j++)
{
    images[j].Save(String.Format(@"Image/Image-{0}.png", i), ImageFormat.Png);
    i++;
}

Screenshot:

How to Extract Image from Signature in PDF

Full code:

[C#]
//Load the PDF document
PdfDocument document = new PdfDocument("sample.pdf");

//Get the existing forms of the document
PdfFormWidget form = document.Form as PdfFormWidget;

//Extract images from signatures in the existing forms
Image[] images = form.ExtractSignatureAsImages();

//Save the images to disk
int i = 0;
for (int j = 0; j < images.Length; j++)
{
    images[j].Save(String.Format(@"Image/Image-{0}.png", i), ImageFormat.Png);
    i++;
}

//Close the document
document.Close();
[VB.NET]
'Load the PDF document
Dim document As New PdfDocument("sample.pdf")

'Get the existing forms of the document
Dim form As PdfFormWidget = TryCast(document.Form, PdfFormWidget)

'Extract images from signatures in the existing forms
Dim images As Image() = form.ExtractSignatureAsImages()

'Save the images to disk
Dim i As Integer = 0
For j As Integer = 0 To images.Length - 1
	images(j).Save([String].Format("Image/Image-{0}.png", i), ImageFormat.Png)
	i += 1
Next

'Close the document
document.Close()