Delete signatures of the certain type

Overview

GroupDocs.Signature provides ability to delete signatures of the certain type from the documents over delete method.
Please be aware that delete method modifies the same document that was passed to constructor of Signature class, so the example below copies the signed document first and deletes the signatures from the copy.

How to delete signatures of the certain type from the document

Here are the steps to delete signatures of the certain type from the document with GroupDocs.Signature:

  • Create new instance of Signature class and pass source document path as a constructor parameter;
  • Call Signature object delete method and pass the SignatureType of the signatures to remove, for example SignatureType.TEXT;
  • Check the returned DeleteResult: its succeeded list holds the deleted signatures and failed holds the signatures that could not be deleted.

This example shows how to delete all text signatures from the document. Only the signatures that GroupDocs.Signature added are deleted; the document’s own text stays as it is.

import shutil

from groupdocs.signature import Signature
from groupdocs.signature.domain import SignatureType

def delete_signatures_by_type():
    # delete() saves the changes into the opened document, so work on a copy
    shutil.copy("signed.docx", "all_text_signatures_deleted.docx")

    with Signature("all_text_signatures_deleted.docx") as signature:
        # Delete every text signature in the document
        result = signature.delete(SignatureType.TEXT)
        print(f"Deleted {len(result.succeeded)} text signature(s), {len(result.failed)} failed")
        for number, deleted in enumerate(result.succeeded, 1):
            print(f"  #{number}: '{deleted.text}' (id {deleted.signature_id})")

if __name__ == "__main__":
    delete_signatures_by_type()
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 sign PDF, Word, Excel, PowerPoint, and other documents you can use the online apps from the GroupDocs.Signature App Product Family.