Delete Digital signatures from documents

Overview

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;
  • Instantiate DigitalSearchOptions object with desired properties;
  • Call search method; the signatures property of the returned SearchResult holds the found DigitalSignature objects;
  • 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.

import shutil

from groupdocs.signature import Signature
from groupdocs.signature.options import DigitalSearchOptions


def delete_digital_signature():
    # delete() saves the changes into the opened document, so work on a copy
    shutil.copy("signed.pdf", "digital_signature_deleted.pdf")

    with Signature("digital_signature_deleted.pdf") as signature:
        signatures = signature.search([DigitalSearchOptions()]).signatures
        print(f"Found {len(signatures)} digital signature(s)")
        if not signatures:
            return

        digital_signature = signatures[0]
        subject = digital_signature.certificate.subject
        if signature.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.

Binary file (PDF, 197 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.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.