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:
Create a new instance of the Signature class and pass the source document path as a parameter.
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:
fromgroupdocs.signatureimportSignaturefromgroupdocs.signature.domainimportFileTypefromgroupdocs.signature.optionsimportImageSearchOptionsdefextract_image_signatures():withSignature("signed.pdf")assignature:options=ImageSearchOptions()# Search the first page onlyoptions.all_pages=Falseoptions.page_number=1# Skip images smaller than 1 KBoptions.min_content_size=1024# Return the image data as PNGoptions.return_content=Trueoptions.return_content_type=FileType.PNGresult=signature.search([options])print(f"Found {len(result.signatures)} matching image signature(s)")fornumber,imageinenumerate(result.signatures,start=1):file_name=f"image_signature_{number}.png"withopen(file_name,"wb")asoutput: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.