Skip to content

fix(ocr): render scanned PDF pages before embedded images - #2348

Open
Elioooon (Elioooon) wants to merge 1 commit into
microsoft:mainfrom
Elioooon:fix/scanned-pdf-page-ocr
Open

fix(ocr): render scanned PDF pages before embedded images#2348
Elioooon (Elioooon) wants to merge 1 commit into
microsoft:mainfrom
Elioooon:fix/scanned-pdf-page-ocr

Conversation

@Elioooon

Copy link
Copy Markdown

Summary

Fixes #2343.

  • render zero-text PDF pages at 300 DPI and OCR the full page before considering embedded images
  • reuse the already-open pdfplumber page for image extraction instead of reopening the whole PDF once per page
  • share the existing full-page render/OCR path between per-page and document fallbacks

This keeps mixed PDFs intact: text pages still interleave extracted text and embedded-image OCR, while scanned pages no longer lose their body content to small decorative images.

Verification

  • python -m pytest packages/markitdown-ocr/tests/test_pdf_converter.py -q -k 'scanned_page_uses_full_page_ocr or convert_reuses_open_page_for_image_extraction' - 2 passed
  • python -m pytest packages/markitdown-ocr/tests -q - 37 passed, 1 pre-existing failure: test_pdf_multipage assumes pdfplumber rejects the fixture, but the current dependency version extracts it successfully; reproduced unchanged on main
  • black==23.7.0 --check packages/markitdown-ocr/src/markitdown_ocr/_pdf_converter_with_ocr.py packages/markitdown-ocr/tests/test_pdf_converter.py - passed
  • git diff --check - passed

Risk

Scoped to the OCR plugin's PDF path. Text-only conversion and non-PDF converters are unchanged. A page is treated as scanned only when page.extract_text() is empty or whitespace.

@Elioooon

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

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.

markitdown-ocr: three PDF bugs — scanned pages never OCR'd, per-page PDF reopen, page-level scan misdetection

1 participant