Verify Barcode Signatures in Document

GroupDocs.Signature for Python via .NET provides functionality to verify barcode signatures in documents. This guide demonstrates how to verify barcode signatures using Python.

Basic Usage Example

Here’s a simple example showing how to verify barcode signatures in a document. The is_valid property of the returned VerificationResult is True when the document contains barcode signatures that match the BarcodeVerifyOptions:

from groupdocs.signature import Signature
from groupdocs.signature.domain import TextMatchType
from groupdocs.signature.options import BarcodeVerifyOptions


def verify_barcode_signatures():
    with Signature("signed.pdf") as signature:
        options = BarcodeVerifyOptions()
        options.all_pages = True  # this value is set by default
        options.text = "12345"
        options.match_type = TextMatchType.CONTAINS

        result = signature.verify(options)

        if result.is_valid:
            print(f"Document was verified successfully: {len(result.succeeded)} matching barcode signature(s).")
        else:
            print("Document failed verification process.")


if __name__ == "__main__":
    verify_barcode_signatures()

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

Document was verified successfully: 1 matching barcode signature(s).

Download full output

Advanced Usage Example

Here’s an example showing more advanced verification options: an exact text match, the barcode type (BarcodeTypes) and the page to verify. The succeeded property of the result lists the barcode signatures that passed verification:

from groupdocs.signature import Signature
from groupdocs.signature.domain import BarcodeTypes, TextMatchType
from groupdocs.signature.options import BarcodeVerifyOptions


def verify_code128_barcode_signature():
    with Signature("signed.pdf") as signature:
        options = BarcodeVerifyOptions()
        options.text = "123456789012"
        options.match_type = TextMatchType.EXACT  # require exact match
        # If the encode type is not set, any barcode type is accepted
        options.encode_type = BarcodeTypes.CODE128
        # Verify the first page only (page numbers start at 1)
        options.all_pages = False
        options.page_number = 1

        result = signature.verify(options)

        print(f"Document is valid: {result.is_valid}")
        for barcode in result.succeeded:
            print(f"Verified {barcode.encode_type.type_name} barcode '{barcode.text}'")


if __name__ == "__main__":
    verify_code128_barcode_signature()

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

Document is valid: True
Verified Code128 barcode '123456789012'

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 verify 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.