2026-11-04 · Tesseract, page images, word positions and ALTO

2026-11-04 · Tesseract, page images, word positions and ALTO

Context

#46 asks for free text extraction on the researcher’s computer, as Whisper already gives for recordings, so that someone who wants to stay local can do so without an account, a key or a provider. Tesseract was planned in the specification’s Offline mode; ALTO XML was planned “where models return coordinates”, and correcting ALTO with its coordinates kept is what iwac-ai-pipelines’ 02_correct_alto_xml.py does. A small OCR vision model (PaddleOCR-VL, GLM-OCR, LightOnOCR) is the next step, tracked in #105.

The issue asks for the architecture checkpoint due before a second implementation of an offline engine. It was held before writing code, against the specification, the roadmap, AGENTS.md and the offline, media, export and engine crates.

Checkpoint findings

Decisions

Tesseract built from source and linked in

Tesseract 5.5.2 and Leptonica 1.87 are compiled by kreuzberg-tesseract (MIT) and linked into the app, through its safe API: the workspace forbids unsafe code. Tesseract is Apache 2.0 and Leptonica BSD-2-Clause, so linking is allowed, unlike FFmpeg’s LGPL; nothing is shipped beside the executable. Their licences are kept in crates/offline/licenses/, since the build script downloads their sources, and third-party-notices.mjs adds them to the notices.

Three things the build needed:

The crate’s build script downloads Tesseract and Leptonica’s tagged sources from GitHub without a checksum. They come from the projects’ own repositories at fixed tags; vendoring them was judged heavier than the risk, and is the fallback if the crate stops being maintained.

Language data

One file per language from tesseract-ocr/tessdata_best at a pinned commit, size and SHA-256 checked as for Whisper, downloaded from Settings into the app’s data folder (tesseract-data). tessdata_best rather than tessdata_fast: the most accurate models, at 3 to 15 MB a language. The 26 languages of Kalamu’s list that Tesseract has a model for get theirs; the Latin-script languages of West and Central Africa it has none for (Hausa, Igbo, Fula, Wolof, Bambara, Dioula, Mooré, Ewe, Fon, Twi, Somali, Lingala, Zulu, Xhosa, Malagasy) read with Tesseract’s Latin script model (101 MB), which covers every language written in Latin letters.

Tesseract does not detect the language. The catalogue says so per model (detects_language); New job then offers no Detect automatically, asks for the languages, and points to Settings for any whose data is missing. Several languages are loaded together (fra+eng).

Tesseract opens its data by a path in the system’s code page. On Windows the app’s manifest now declares UTF-8 as that code page, so a user folder with accents (C:\Users\Frédérick) works; Tauri’s own manifest content is kept. The manifest is set in src-tauri/build.rs, since Tauri’s configuration has no field for it.

PDF pages drawn with hayro

A PDF page is drawn at 300 dpi when the model reads images only, from the same single-page PDF the other models are sent, so a split spread is drawn as the half they read. hayro (MIT or Apache 2.0) is a PDF rasterizer written in Rust that forbids unsafe code; PDFium would have meant a library shipped beside the app on each of the three systems, with its loading and packaging. hayro does not open encrypted PDFs (neither does lopdf, which already refuses them) and its authors warn that malformed files can still exhaust time or memory; a page that fails is reported like any other failed piece. The specification now names hayro.

Word positions and corrections

TextRegion keeps its block and gains lines, each with its words and the engine’s confidence. Tesseract fills them from its TSV output; Mistral OCR still gives blocks only. A corrected page used to collapse into one block over the page. Its words are now laid back onto the boxes of the words the engine read (engine/src/realign.rs), ported from 02_correct_alto_xml.py: there the model corrects line by line and the corrected words are written into the original String elements; here the researcher’s whole page is matched to the engine’s words by a diff, a changed word taking the box of the one it replaces, added words sharing the box before them, removed words leaving theirs empty. Kalamu differs in matching by diff because its corrections are free text typed by a person, not one answer per line.

ALTO

ALTO 4, one file per document, a Page per page, positions in pixels (of the image, or of the page at 300 dpi for a PDF), each word with its confidence where the engine gave one. Offered, like the searchable PDF, only from a model that reports layout (ExportFormat::needs_layout). From Mistral OCR the lines share their block’s height and the words their line’s width, and the file says those positions are estimated. The searchable PDF now sets each of Tesseract’s lines over its own box.

Consequences