Skip to content

feat: add OCR fallback for scanned PDF pages - #40

Merged
n0nuser merged 1 commit into
mainfrom
feat/pdf-ocr-ingestion
Jul 6, 2026
Merged

feat: add OCR fallback for scanned PDF pages#40
n0nuser merged 1 commit into
mainfrom
feat/pdf-ocr-ingestion

Conversation

@n0nuser

@n0nuser n0nuser commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • PDF ingestion previously relied solely on pypdf text extraction, which silently returns empty text for scanned/image-only pages.
  • Pages whose extracted text is shorter than OCR_MIN_CHARS_PER_PAGE are now rasterized with pypdfium2 and OCR'd with Tesseract via pytesseract. OCR failures (e.g. missing tesseract binary) fall back to the original text rather than raising.
  • New settings: OCR_ENABLED (default true), OCR_LANGUAGE (default eng), OCR_MIN_CHARS_PER_PAGE (default 20).
  • Docker image installs tesseract-ocr.
  • New docs/ocr.md, plus updates to docs/architecture.md / docs/agent-navigation.md per the repo's doc-maintenance rule.

Test plan

  • uv run pytest -q — 93 passed (adds tests/test_pdf_ocr.py, 4 new unit tests with mocked OCR/pdfium)
  • uv run ruff format --check . / uv run ruff check . — clean
  • uv run mypy localrag/ --ignore-missing-imports --no-strict-optional — clean
  • Built the Docker image and confirmed tesseract is installed and on PATH
  • Generated a real image-only PDF (no text layer) and ran it through parse_pdf inside the container — OCR correctly extracted the embedded text end-to-end

pypdf's text extraction returns empty text for image-only/scanned PDF
pages, silently dropping their content during ingestion. Pages whose
extracted text falls below OCR_MIN_CHARS_PER_PAGE are now rasterized
with pypdfium2 and read with Tesseract via pytesseract; OCR failures
(e.g. missing tesseract binary) fall back to the original text instead
of raising. Adds OCR_ENABLED/OCR_LANGUAGE/OCR_MIN_CHARS_PER_PAGE
settings, installs tesseract-ocr in the Docker image, and documents
the feature in docs/ocr.md.
@n0nuser
n0nuser merged commit dad18f8 into main Jul 6, 2026
8 checks passed
@n0nuser
n0nuser deleted the feat/pdf-ocr-ingestion branch July 6, 2026 20:00
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