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#]
using Spire.Pdf;
using Spire.Pdf.Widget;
using System;
using System.Drawing;
using System.Drawing.Imaging;


namespace ExtractImage
{
    class Program
    {
        static void Main(string[] args)
        {
            //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]
Imports Spire.Pdf
Imports Spire.Pdf.Widget
Imports System.Drawing
Imports System.Drawing.Imaging


Namespace ExtractImage
	Class Program
		Private Shared Sub Main(args As String())
			'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()
		End Sub
	End Class
End Namespace