v0.5.0 — OCR + render-backend pipeline (100% on insurance corpus) - #4
Merged
Merged
Conversation
Pages with no extractable text — scanner output, "Microsoft Print To PDF"
exports, image-only PDFs — can now be rasterized + OCR'd transparently.
Two render backends + two OCR backends ship; the interfaces let callers
plug in any provider.
Real-world impact (insurance corpus, 12 docs)
🟢 ≥70 🟡 30-69 🔴 <30
Without OCR (v0.4) 6 6 0
With OCR (Poppler+Tesseract) 12 0 0 ← all docs handled
Architecture
- OcrBackend / RenderBackend interfaces. Minimal, plug-and-play.
- convertPdf({ ocr: { render, ocr, mode } }) — opt-in pipeline:
'auto' (default) — OCR only pages with no extractable text
'always' — OCR every page (overrides extracted text)
'never' — disable OCR entirely
- Pages with extractable text are not re-OCR'd in 'auto' mode (cost
optimization), making mixed text+image PDFs cheap.
- document.ocr_used flag set to true when OCR was applied.
- Capabilities map: ocr: true on snapshots produced via OCR.
Bundled render backends
- PopplerRenderBackend — shells out to pdftoppm. Lightest, no native modules.
- PdfjsRenderBackend — pure-Node via pdfjs-dist + node-canvas (optional).
Bundled OCR backends
- TesseractOcrBackend — in-process WASM. Free, offline, ~10s/page.
Long-lived worker reused across pages; close()
terminates it. Honors language hint.
- MistralOcrBackend — cloud API. ~$1/1k pages, best quality. Auth
via MISTRAL_API_KEY env var or constructor opt.
Bring-your-own — AWS Textract, Google Document AI, Apple Vision Framework,
etc. all fit the same OcrBackend / RenderBackend shape. Reference impls
welcome via PR.
Devex
- examples/ocr-pdf.ts demonstrates Poppler + Tesseract end-to-end.
- examples/diagnose-pdf.ts gains a --ocr flag; quality scores reflect
whether OCR rescued otherwise-failing docs.
Tests
- 8 new OCR pipeline tests with mocked backends (deterministic, fast).
- Total: 176 unit + 10 real-Chromium = 186 (was 176).
Optional peer deps
- tesseract.js@^5 (Tesseract backend)
- canvas (PdfjsRenderBackend)
- pdfjs-dist@^4 (already opt-peer; required for both render backends and
text extraction generally)
Not in this release
- AWS Textract / Google Document AI / Apple Vision adapters — interface
ships, community impls welcome
- Form-structure inference (label/value pairs on non-AcroForm PDFs) —
paired with M3 / v0.6
- AcroForm support — M3 / v0.6
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 10, 2026
This was referenced May 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pages with no extractable text — scanner output, "Microsoft Print To PDF" exports, image-only PDFs — can now be rasterized + OCR'd transparently. Two render backends + two OCR backends ship; the interfaces let callers plug in any provider.
Stacked on top of #3 (M2). Merge #2 → #3 → this PR in order.
Real-world impact
12-doc insurance corpus (the same one used to drive M2 design):
Failing categories before — all now resolved by OCR:
Sample output from an Erie Auto Quote PDF (was: 0 text items extracted; now: a full structured snapshot):
Architecture
```
PDF page ──[RenderBackend]──► PNG/JPEG bytes ──[OcrBackend]──► Text + positions
```
Bundled backends
Render:
OCR:
Bring-your-own (AWS Textract, Google Document AI, Apple Vision) all fit the same interface.
Tests
Test plan
🤖 Generated with Claude Code