qrdm.decode_qr_pdf

qrdm.decode_qr_pdf(input_file: str | Path | bytes | BytesIO, *, reject_unexpected_codes: bool = False, strict: bool = False, max_payload_size: int = 5242880) → DocumentPayload[source]

Decode a QRDM PDF into the original document content and metadata.

Parameters:

input_file (Path-like, bytes, or io.BytesIO) – Path to PDF file, binary stream, or bytes containing the file contents of the QR PDF. (e.g. as returned by encode_qr_pdf) Passed as input to the fitz.open function provided by PyMuPDF.

Returns:

decoded_document – A Pydantic model containing the encoded document & metadata, with attributes:

  • content: str - Source document contents

  • metadata: JsonValue, optional - Document metadata, as provided to the metadata argument of the encoding.

Return type:

DocumentPayload

Raises:

QRDecodeError – If no QR codes are detected in the PDF, if insufficient QR codes are recovered, or if checksum verification fails.

Examples

>>> qrdm.encode_qr_pdf(
...     "Lorem ipsum dolor sit amet. 😎",
...     metadata={"example": True},
...     path="example_qr_pdf.pdf",
... )
>>> qrdm.decode_qr_pdf("example_qr_pdf.pdf")
DocumentPayload(content='Lorem ipsum dolor sit amet. 😎', metadata={'example': True})