Update Image Signatures in Document

GroupDocs.Signature for Python via .NET provides functionality to manipulate image signatures’ location, size, and other properties. Please note that the update method modifies the same document that was passed to the constructor of the Signature class, so the example below copies the signed document first and updates the copy.

Here are the steps to update an Image signature in a document with GroupDocs.Signature:

  • Create a new instance of the Signature class and pass the source document path as a constructor parameter
  • Instantiate the ImageSearchOptions object with desired properties
  • Call the search method; the signatures property of the returned SearchResult holds the found image signatures
  • Select from the list the ImageSignature object(s) that should be updated and change their properties
  • Call the Signature object’s update method and pass one or several signatures to it; for a single signature it returns True when the signature was updated

This example shows how to update an Image signature that was found using the search method:

import shutil

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


def update_image_signature():
    # update() saves the changes into the opened document, so work on a copy
    shutil.copy("signed.docx", "updated_image_signature.docx")

    with Signature("updated_image_signature.docx") as signature:
        options = ImageSearchOptions()
        # Return only signatures added by GroupDocs.Signature, not the document's own images
        options.skip_external = True
        signatures = signature.search([options]).signatures
        print(f"Found {len(signatures)} image signature(s)")
        if not signatures:
            return

        image_signature = signatures[0]
        # Change the position
        image_signature.left = 240
        image_signature.top = 450
        # Change the size. Not all document formats support resizing a signature
        image_signature.width = 150
        image_signature.height = 125

        if signature.update(image_signature):
            print(f"Image signature moved to ({image_signature.left}, {image_signature.top}) "
                  f"and resized to {image_signature.width}x{image_signature.height}")
        else:
            print("Image signature was not updated")


if __name__ == "__main__":
    update_image_signature()

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

Binary file (DOCX, 147 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 generate image signatures and/or sign your files with them for free, you can use the Generate Image online app.

To sign PDF, Word, Excel, PowerPoint, and other documents you can use the other 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.