How It Works¶
This part of the documentation gives a high-level overview of how invoice2data turns a PDF (or image) into structured data.
1. Text extraction¶
invoice2data extracts text with a pluggable backend. By default it tries an
ordered cascade — pdfium first (a self-contained wheel, no system binaries),
then pdftotext — and falls back to OCR (ocrmypdf) as a last resort. You can
force a backend with --input-reader, and a template can pin the backend it was
authored for with a top-level input_module:. See Installation for the
optional backends (docTR, PaddleOCR, Google Vision, …).
2. Template matching¶
YAML or JSON templates describe each invoice layout. A template is selected by
matching its keywords against the extracted text; regular expressions then
locate the fields. The system is flexible: static fields, multiple regexes per
field, line-item and table plugins, and per-field options.
3. Data extraction¶
The matched template’s regexes (and the lines/tables/camelot plugins) pull
the values out of the optimized text. Results are then normalised to the
canonical field schema and lightly validated (typo-aware field names, tax
totals); see Recommended fields.
4. Optional AI fallback¶
When no template matches — or a match misses required fields — an optional, configured LLM can extract the canonical fields instead. This is opt-in and text-only; see AI features.
5. Output¶
The structured data is written as CSV, JSON or XML, or used to rename the source PDF based on its contents.