Recover PDF text truncated by inline images using PyMuPDF fallback#2092
Open
Muhtasim-Munif-Fahim wants to merge 3 commits into
Open
Recover PDF text truncated by inline images using PyMuPDF fallback#2092Muhtasim-Munif-Fahim wants to merge 3 commits into
Muhtasim-Munif-Fahim wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds an optional PyMuPDF-based text extraction fallback to improve PDF conversion when primary extractors (pdfplumber/pdfminer) appear to return truncated text, particularly around inline images.
Changes:
- Introduces an optional PyMuPDF extraction path and heuristics to prefer it when primary output looks truncated.
- Adds a regression test to validate choosing PyMuPDF when primary extraction misses post-image text.
- Documents and packages PyMuPDF as an optional extra (and includes it in the
allextra).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/markitdown/tests/test_module_misc.py | Adds a test that simulates truncation and asserts the PyMuPDF path is preferred. |
| packages/markitdown/src/markitdown/converters/_pdf_converter.py | Adds PyMuPDF extraction helper and selection heuristics based on images + output length. |
| packages/markitdown/pyproject.toml | Adds pymupdf optional dependency (extra + included in all). |
| packages/markitdown/README.md | Documents how to install the optional PyMuPDF extra. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0a99efc to
60c5aa8
Compare
60c5aa8 to
07d779c
Compare
Author
|
@microsoft-github-policy-service agree |
- Patch the module-level `fitz` name in the test instead of an attribute on it, since `fitz` is `None` when PyMuPDF isn't installed and `monkeypatch.setattr(None, "open", ...)` raises AttributeError. - Avoid buffering the PDF twice: pass a zero-copy `getbuffer()` view to fitz.open() instead of `pdf_bytes.read()`, which duplicated the whole file in memory. - Extract the magic thresholds (2048, 1.5, 200) into named module-level constants.
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.
Fixes #1870.
Some PDFs with inline images cause pdfplumber/pdfminer to silently drop text that appears after the image. When the primary extraction path returns a much shorter body on image-bearing pages, this change optionally retries with PyMuPDF and prefers that output if it is substantially longer.
Also documents the optional pymupdf extra and adds a regression test that simulates the truncation path.