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:
fromgroupdocs.signatureimportSignaturefromgroupdocs.signature.domainimportTextMatchTypefromgroupdocs.signature.optionsimportBarcodeVerifyOptionsdefverify_barcode_signatures():withSignature("signed.pdf")assignature:options=BarcodeVerifyOptions()options.all_pages=True# this value is set by defaultoptions.text="12345"options.match_type=TextMatchType.CONTAINSresult=signature.verify(options)ifresult.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).
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:
fromgroupdocs.signatureimportSignaturefromgroupdocs.signature.domainimportBarcodeTypes,TextMatchTypefromgroupdocs.signature.optionsimportBarcodeVerifyOptionsdefverify_code128_barcode_signature():withSignature("signed.pdf")assignature:options=BarcodeVerifyOptions()options.text="123456789012"options.match_type=TextMatchType.EXACT# require exact match# If the encode type is not set, any barcode type is acceptedoptions.encode_type=BarcodeTypes.CODE128# Verify the first page only (page numbers start at 1)options.all_pages=Falseoptions.page_number=1result=signature.verify(options)print(f"Document is valid: {result.is_valid}")forbarcodeinresult.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'