The code snippet below demonstrates how to search for QR-code signatures in a document using Python:
fromgroupdocs.signatureimportSignaturefromgroupdocs.signature.optionsimportQrCodeSearchOptionsdefsearch_qr_codes():withSignature("signed.pdf")assignature:result=signature.search([QrCodeSearchOptions()])print(f"Found {len(result.signatures)} QR code signature(s)")forqr_codeinresult.signatures:print(f"QR code signature found at page {qr_code.page_number} "f"with type {qr_code.encode_type.type_name} and text '{qr_code.text}'")if__name__=="__main__":search_qr_codes()
signed.pdf is the sample file used in this example. Click here to download it.
Found 1 QR code signature(s)
QR code signature found at page 1 with type QR and text 'John Smith'
Here’s an example showing how to use more advanced search options for QR codes: a page to search, the QR code type (QrCodeTypes) and the text to match.
fromgroupdocs.signatureimportSignaturefromgroupdocs.signature.domainimportQrCodeTypes,TextMatchTypefromgroupdocs.signature.optionsimportQrCodeSearchOptionsdefsearch_qr_codes_with_filters():withSignature("signed.pdf")assignature:options=QrCodeSearchOptions()# Search the first page only (page numbers start at 1)options.all_pages=Falseoptions.page_number=1# Return only QR codes of the QR type...options.encode_type=QrCodeTypes.QR# ...whose text contains "John"options.text="John"options.match_type=TextMatchType.CONTAINSresult=signature.search([options])print(f"Found {len(result.signatures)} matching QR code signature(s)")forqr_codeinresult.signatures:print(f"Text: {qr_code.text}")print(f"Page number: {qr_code.page_number}")print(f"Position: X={qr_code.left}, Y={qr_code.top}")print(f"Size: {qr_code.width}x{qr_code.height}")print(f"Encode type: {qr_code.encode_type.type_name}")if__name__=="__main__":search_qr_codes_with_filters()
signed.pdf is the sample file used in this example. Click here to download it.
Found 1 matching QR code signature(s)
Text: John Smith
Page number: 1
Position: X=270, Y=370
Size: 100x100
Encode type: QR