cadrumo.application.ledger.evidence_textlayer module

On-host text-layer extraction from in-memory evidence bytes.

Runs the required application page-text capability over a resolved EvidenceInput’s in-memory bytes, fully on-host. Nothing is written to disk and nothing leaves the machine (sensitive-financial-data-secure-storage-only). This is the cheapest on-host reader and covers text-native PDFs; image evidence and scan-only PDFs have no usable text layer and must go through the on-host vision reader instead. The concrete PDF reader is bound by outer composition.

This module is the deterministic half of the ingestion pipeline’s acquisition stage: transcribe_text_layer() projects the extracted pages into a DocumentTranscription, the typed record every later stage reads instead of the bytes. The projection transforms nothing. Reading order is the extractor’s page order, and printed forms survive verbatim: 2.420,00 stays 2.420,00, because the grounding stage verifies a candidate value by finding its printed form in this text, so normalising here would delete the evidence that check runs against.

TEXT_LAYER_TRANSCRIBER_NAME

The concrete reader behind the deterministic acquisition path.

Names the library that actually maps bytes to text rather than a coarse label like text-layer: two extractors disagree on reading order and on where a ligature or a thousands separator lands, so which one produced a transcription is exactly what the provenance stamp exists to record.

text_layer_transcriber_identity()[source]

Return the provenance stamp for the deterministic text-layer read.

Return type:

TranscriberIdentity

extract_evidence_pages(evidence, *, text_layer_ports)[source]

Return the on-host text layer of a PDF EvidenceInput, page by page.

Parameters:
Return type:

tuple[str, ...]

Returns:

One string per page in the document’s own page order. A page carrying no text keeps its slot as the empty string, so the tuple length is the page count and the reading order is positional.

Raises:

PurchaseInvoiceEvidenceInputError – When the evidence is not a PDF, or the PDF has no usable text layer (scan-only / XFA) – the caller falls back to the on-host vision reader in that case.

extract_evidence_text(evidence, *, text_layer_ports)[source]

Return the on-host text layer of a PDF EvidenceInput as one string.

Parameters:
Return type:

str

Returns:

The concatenated per-page text of the PDF (empty pages dropped).

Raises:

PurchaseInvoiceEvidenceInputError – When the evidence is not a PDF, or the PDF has no usable text layer (scan-only / XFA).

transcribe_text_layer(evidence, *, text_layer_ports)[source]

Return the acquisition-stage transcription of a text-native PDF.

The deterministic acquisition path: it reads, it does not interpret. The text is the extractor’s own output joined in page order with nothing rewritten, so every printed form the document carries reaches the grounding stage intact.

Parameters:
Return type:

DocumentTranscription

Returns:

The transcription, stamped TEXT_LAYER with the extractor that produced it and content-addressed to the source bytes.

Raises:

PurchaseInvoiceEvidenceInputError – When the evidence is not a PDF, or the PDF has no usable text layer (scan-only / XFA).