GroupDocs.Signature for Python via .NET provides functionality to verify QR code signatures in documents. This guide demonstrates how to verify QR code signatures using Python.
Basic Usage Example
Here’s a simple example showing how to verify QR code signatures in a document. The is_valid property of the returned VerificationResult is True when the document contains QR code signatures that match the QrCodeVerifyOptions:
fromgroupdocs.signatureimportSignaturefromgroupdocs.signature.domainimportTextMatchTypefromgroupdocs.signature.optionsimportQrCodeVerifyOptionsdefverify_qr_codes():withSignature("signed.pdf")assignature:options=QrCodeVerifyOptions()options.all_pages=True# this value is set by defaultoptions.text="John"options.match_type=TextMatchType.CONTAINSresult=signature.verify(options)ifresult.is_valid:print(f"Document was verified successfully: {len(result.succeeded)} matching QR code signature(s).")else:print("Document failed verification process.")if__name__=="__main__":verify_qr_codes()
signed.pdf is the sample file used in this example. Click here to download it.
Document was verified successfully: 1 matching QR code signature(s).
Here’s an example showing more advanced verification options: an exact text match, the QR code type (QrCodeTypes) and the page to verify. The succeeded property of the result lists the QR code signatures that passed verification:
fromgroupdocs.signatureimportSignaturefromgroupdocs.signature.domainimportQrCodeTypes,TextMatchTypefromgroupdocs.signature.optionsimportQrCodeVerifyOptionsdefverify_qr_codes_exact_match():withSignature("signed.pdf")assignature:options=QrCodeVerifyOptions()options.text="John Smith"options.match_type=TextMatchType.EXACT# require exact match# If the encode type is not set, any QR code type is acceptedoptions.encode_type=QrCodeTypes.QR# 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}")forqr_codeinresult.succeeded:print(f"Verified {qr_code.encode_type.type_name} code '{qr_code.text}'")if__name__=="__main__":verify_qr_codes_exact_match()
signed.pdf is the sample file used in this example. Click here to download it.
Document is valid: True
Verified QR code 'John Smith'