GroupDocs.Signature for Python via .NET provides functionality to manipulate text signatures’ location, size, and textual content. 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 a Text 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
Call the search method; the signatures property of the returned SearchResult holds the found text signatures
Select from the list the TextSignature 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 a Text signature that was found using the search method:
importshutilfromgroupdocs.signatureimportSignaturefromgroupdocs.signature.optionsimportTextSearchOptionsdefupdate_text_signature():# update() saves the changes into the opened document, so work on a copyshutil.copy("signed.docx","updated_text_signature.docx")withSignature("updated_text_signature.docx")assignature:options=TextSearchOptions()# Return only signatures added by GroupDocs.Signature, not the document's own textoptions.skip_external=Truesignatures=signature.search([options]).signaturesprint(f"Found {len(signatures)} text signature(s)")ifnotsignatures:returntext_signature=signatures[0]old_text=text_signature.text# Change the texttext_signature.text="John Walkman"# Change the positiontext_signature.left=text_signature.left+10text_signature.top=text_signature.top+10# Change the size. Not all document formats support resizing a signaturetext_signature.width=200text_signature.height=100ifsignature.update(text_signature):print(f"Updated '{old_text}' to '{text_signature.text}' at "f"({text_signature.left}, {text_signature.top}), "f"size {text_signature.width}x{text_signature.height}")else:print(f"Text signature '{old_text}' was not updated")if__name__=="__main__":update_text_signature()
signed.docx is the sample file used in this example. Click here to download it.
Not every document format accepts every change. In PDF documents, a text signature added with the default (native) implementation can be moved, but its text and size stay as they were, although update still returns True. Text signatures added to a PDF as annotations or stickers accept text, position and size changes.
More Resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples: