Delete Barcode signatures from documents

Overview

GroupDocs.Signature provides BarcodeSignature class to manipulate barcode 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.

How to delete Barcode signature from the document

Here are the steps to delete Barcode signature from the document with GroupDocs.Signature:

  • Create new instance of Signature class and pass source document path as a constructor parameter;
  • Instantiate BarcodeSearchOptions object with desired properties;
  • Call search method; the signatures property of the returned SearchResult holds the found BarcodeSignature objects;
  • Select from list BarcodeSignature 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 Barcode signature that was found using search method.

import shutil

from groupdocs.signature import Signature
from groupdocs.signature.options import BarcodeSearchOptions


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

    with Signature("barcode_signature_deleted.docx") as signature:
        options = BarcodeSearchOptions()
        # Return only signatures added by GroupDocs.Signature, not barcodes that are part of the document
        options.skip_external = True
        signatures = signature.search([options]).signatures
        print(f"Found {len(signatures)} barcode signature(s)")
        if not signatures:
            return

        barcode_signature = signatures[0]
        if signature.delete(barcode_signature):
            print(f"Deleted barcode '{barcode_signature.text}' ({barcode_signature.encode_type.type_name})")
        else:
            print(f"Barcode '{barcode_signature.text}' was not deleted")


if __name__ == "__main__":
    delete_barcode_signature()

signed.docx is the sample file used in this example. Click here to download it.

Binary file (DOCX, 146 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.