Search for Image e-Signatures

GroupDocs.Signature provides the ability to search for image electronic signatures in documents. Image signatures allow you to add visual elements like logos, stamps, or handwritten signatures to your documents.

What is an Image Signature?

An image signature is a graphical element that can be added to a document to represent a signature. It can be:

  • A scanned handwritten signature
  • A company logo
  • A stamp or seal
  • Any other graphical element used for signing

How to Search for Image Signatures

The Signature class provides the search method which allows you to search for image signatures in documents. Here’s how to use it:

  1. Create a new instance of the Signature class and pass the source document path as a parameter.
  2. Create an instance of ImageSearchOptions class.
  3. Call the search method of the Signature class instance and pass a list with the search options to it.
  4. Process the search results: the signatures property of the returned SearchResult holds the found ImageSignature objects.

Here’s an example of how to search for image signatures in a document:

from groupdocs.signature import Signature
from groupdocs.signature.options import ImageSearchOptions


def search_images():
    with Signature("signed.pdf") as signature:
        result = signature.search([ImageSearchOptions()])

        print(f"Found {len(result.signatures)} image signature(s)")
        for image in result.signatures:
            print(f"Page {image.page_number}: {image.size} bytes at ({image.left}, {image.top}), "
                  f"size {image.width}x{image.height}")


if __name__ == "__main__":
    search_images()

signed.pdf is the sample file used in this example. Click here to download it.

Found 1 image signature(s)
Page 1: 14552 bytes at (50, 415), size 150x50

Download full output

Advanced Search Options

You can customize the search process with the properties of ImageSearchOptions:

  • min_content_size and max_content_size limit the size of the image data, in bytes;
  • return_content returns the image data in the content property of each found signature, and return_content_type converts it to the given FileType;
  • all_pages and page_number search a single page instead of the whole document (page numbers start at 1).

This example saves every image signature found on the first page to a PNG file:

from groupdocs.signature import Signature
from groupdocs.signature.domain import FileType
from groupdocs.signature.options import ImageSearchOptions


def extract_image_signatures():
    with Signature("signed.pdf") as signature:
        options = ImageSearchOptions()
        # Search the first page only
        options.all_pages = False
        options.page_number = 1
        # Skip images smaller than 1 KB
        options.min_content_size = 1024
        # Return the image data as PNG
        options.return_content = True
        options.return_content_type = FileType.PNG

        result = signature.search([options])

        print(f"Found {len(result.signatures)} matching image signature(s)")
        for number, image in enumerate(result.signatures, start=1):
            file_name = f"image_signature_{number}.png"
            with open(file_name, "wb") as output:
                output.write(image.content)
            print(f"Saved {file_name} ({len(image.content)} bytes)")


if __name__ == "__main__":
    extract_image_signatures()

signed.pdf is the sample file used in this example. Click here to download it.

Binary file (PNG, 14 KB)

Download full output

More Resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online Apps

Along with the full-featured Python library, we provide simple but powerful free online apps.

To sign PDF, Word, Excel, PowerPoint, and other documents you can use the online apps from the GroupDocs.Signature App Product Family.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.