Fix OCR for mixed text and scanned PDF pages#1888
Open
haosenwang1018 wants to merge 1 commit into
Open
Conversation
|
@haosenwang1018 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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.
Issue
Closes #1791
Root cause
When an OCR-enabled PDF has at least one extractable text page, the converter builds non-empty markdown from that page and never reaches the whole-document scanned-PDF fallback. Later pages that have no embedded image objects and no text layer are left as page headers only.
Fix
Render and OCR an individual page when OCR is enabled, no embedded images are detected, and the page text layer is empty. This keeps text-layer pages on the existing path while recovering mixed scanned pages.
Tests
uv run --project packages/markitdown-ocr --with-editable packages/markitdown --with pytest python -m pytest packages/markitdown-ocr/tests/test_pdf_converter.py -k 'mixed_text_and_scanned_pages or scanned_report or scanned_fallback_format'test_pdf_converter.pyfile in this local uv environment gives 13/14 passing; the remaining existingtest_pdf_multipageexpectation assumes pdfplumber fails on that fixture, but pdfplumber parses it successfully here before this change.