Skip to content

feat(core,ocr-tesseract): read scanned PDFs by OCR (extension 0.8.0) - #311

Merged
russoedu merged 4 commits into
mainfrom
feat/pdf-ocr
Oct 17, 2026
Merged

russoedu merged 4 commits into
mainfrom
feat/pdf-ocr

Conversation

@russoedu

Copy link
Copy Markdown
Collaborator

What

A request for a PDF takes "ocr": true or { languages?, always?, dpi? }. Pages with no text layer are read by OCR and their words become the same positioned cells a text layer gives, so table, region and section work on scans.

  • @opencraw/core: pdf-ocr slice (OCR contract, page rendering with pdf.js + @napi-rs/canvas, words to runs), ocr on the request step, schema, docs. A scan read without ocr now says how to ask for it.
  • New @opencraw/ocr-tesseract: Tesseract (WebAssembly, bundled English model; other languages from @tesseract.js-data/<code>). Each page is cleaned first (background flattening, deskew, and a second adaptive-binarize + median pass when the first read is poor); word boxes map back to the original page.
  • Bundled in the VS Code extension (0.8.0).

Measured

Rendering at the scan's native dpi (150 to 300) matters: upsampling a soft 144 dpi scan to 300 read nothing. The tilted, shaded fixture read nothing with the plain cleaning and reads with the second pass (one character off: 8,0% as 8,09). The per-pixel loops avoid Math.* calls, which cost ~100x more inside Jest (cleanup 14 s to 0.3 s).

Test plan

  • ocr-tesseract suite (17 tests, real Tesseract against generated fixtures) and a file: request with ocr: true end to end
  • core lint/test/build; nx affected lint/test/typecheck
  • CI incl. extension e2e/package with the new package in the VSIX

🤖 Generated with Claude Code

https://claude.ai/code/session_01TjR6eM2tUwU3NGnKXsmEap

russoedu and others added 4 commits October 17, 2026 02:13
…request

A request for a PDF takes "ocr": true or { languages, always, dpi }.
Pages with no text layer are rendered at the scan's own resolution
(150 to 300 dpi), cleaned (background flattened, straightened, and
binarized when the first read is poor), read by Tesseract and handed on
as positioned text runs, so table, region and section work on a scan.

The engine is the new @opencraw/ocr-tesseract package, loaded when a
recipe asks for it and bundled in the extension.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TjR6eM2tUwU3NGnKXsmEap
@russoedu
russoedu merged commit b3fa540 into main Oct 17, 2026
6 checks passed
@russoedu
russoedu deleted the feat/pdf-ocr branch October 17, 2026 01:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant