QR, Bar Codes
Note
It’s required to install codes
from Optional dependencies section.
Extractor & Decoder
- class aiviro.modules.codes.CodesExtractor(pdf_data: PDFRobot | PDFConvertor | List[ndarray] | None = None)
Codes extractor detects and extracts QR and Bar codes from PDFs and images. For list of supported codes, see https://pypi.org/project/pyzbar/ package documentation.
- Parameters:
pdf_data – Source of the image data for processing
- Example:
>>> from aiviro.modules.pdf import create_pdf_robot >>> from aiviro.modules.codes import CodesExtractor >>> r = create_pdf_robot("path/to/file.pdf") >>> ce = CodesExtractor(r) >>> qr_codes = ce.qr_codes(page=1) >>> bar_codes = ce.bar_codes(page=0)
>>> from aiviro.modules.codes import ZBarSymbol >>> r = create_pdf_robot("path/to/file.pdf") >>> ce = CodesExtractor(r) >>> custom_codes = ce.any_codes(code_types=[ZBarSymbol.PDF417])
- qr_codes(page: int = 0) List[CodeData]
Extracts QR codes.
- Parameters:
page – Index of the page to process
- bar_codes(page: int = 0) List[CodeData]
Extracts Bar codes.
- Parameters:
page – Index of the page to process
- any_codes(page: int, code_types: List[ZBarSymbol]) List[CodeData]
Extracts any of the supported codes.
- Parameters:
page – Index of the page to process
code_types – Types of codes to extract
Czech Invoice Format
- class aiviro.modules.codes.CzechQRInvoiceDecoder
Decodes QR data based on https://qr-faktura.cz/ format definition. See
CzechQRInvoiceData
for further information.- Example:
>>> from aiviro.modules.pdf import create_pdf_robot >>> from aiviro.modules.codes import CodesExtractor, CzechQRInvoiceDecoder >>> r = create_pdf_robot("path/to/file.pdf") >>> qr_data = CodesExtractor(r).qr_codes() >>> if qr_data: >>> decoded_data = CzechQRInvoiceDecoder().decode(qr_data[0]) >>> invoice_id = decoded_data.get_value("ID")