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.
importshutilfromgroupdocs.signatureimportSignaturefromgroupdocs.signature.domainimportSignatureTypedefdelete_signatures_by_type():# delete() saves the changes into the opened document, so work on a copyshutil.copy("signed.docx","all_text_signatures_deleted.docx")withSignature("all_text_signatures_deleted.docx")assignature:# Delete every text signature in the documentresult=signature.delete(SignatureType.TEXT)print(f"Deleted {len(result.succeeded)} text signature(s), {len(result.failed)} failed")fornumber,deletedinenumerate(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.