GroupDocs.Signature provides DigitalSignature class to manipulate digital signatures and delete them 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 signature from the copy.
Important information. Please be aware that digitally signed documents with valid certificates (pfx files) are secured and verified. Changing digitally signed document makes them untrusted from the digital verification perspective. At this moment only Pdf documents support deletion of the specific digital signatures in case of many ones were added. Most documents support deletion of all digital signatures at once without separate certificates removal. It’s strongly recommended to delete digital signatures by the SignatureType.DIGITAL signature type. See the example Delete signatures of the certain type.
How to delete Digital signature from the document
Here are the steps to delete Digital signature from the document with GroupDocs.Signature:
Create new instance of Signature class and pass source document path as a constructor parameter;
Select from list DigitalSignature object(s) that should be removed from the document;
Call Signature object delete method and pass one or several signatures to it; for a single signature it returns True when the signature was deleted.
This example shows how to delete Digital signature that was found using search method.
importshutilfromgroupdocs.signatureimportSignaturefromgroupdocs.signature.optionsimportDigitalSearchOptionsdefdelete_digital_signature():# delete() saves the changes into the opened document, so work on a copyshutil.copy("signed.pdf","digital_signature_deleted.pdf")withSignature("digital_signature_deleted.pdf")assignature:signatures=signature.search([DigitalSearchOptions()]).signaturesprint(f"Found {len(signatures)} digital signature(s)")ifnotsignatures:returndigital_signature=signatures[0]subject=digital_signature.certificate.subjectifsignature.delete(digital_signature):print(f"Deleted the digital signature of '{subject}', signed on {digital_signature.sign_time}")else:print(f"Digital signature of '{subject}' was not deleted")if__name__=="__main__":delete_digital_signature()
signed.pdf is the sample file used in this example. Click here to download it.