fix: add support of scanned pdf with broken xref#118
Merged
Allob merged 4 commits intodevelopmentfrom Feb 27, 2026
Merged
Conversation
Allob
commented
Feb 26, 2026
Allob
commented
Feb 26, 2026
Allob
commented
Feb 26, 2026
Allob
commented
Feb 26, 2026
Allob
commented
Feb 26, 2026
adubovik
reviewed
Feb 26, 2026
adubovik
reviewed
Feb 26, 2026
adubovik
previously approved these changes
Feb 26, 2026
adubovik
approved these changes
Feb 27, 2026
Allob
added a commit
that referenced
this pull request
Feb 27, 2026
Allob
added a commit
that referenced
this pull request
Feb 27, 2026
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.
Applicable issues
Description of changes
Add support of scanned pdf with broken xref table.
The pdfplumber library (and may others) is unable to read this pdf, because it is unable to find pages catalog using xref table.
But pdfplumber uses pypdfium2 to render page images. Pypdfium2 is able to read pdfs with broken xref by sequential scan.
This PR makes PdfPageImageExtractor to use pypdfium2 directly, without pdfplumber wrapper. This causes additional changes:
extract_number_of_pages is not async, to run pypdfium2 operations in single thread, since extract_number_of_pages implementation using pypdfium2 is not thread-safe. This caused add_image_only_chunks and add_sources to be moved from get_document_chunks (non-async, within executor), to parse_document (async).
The extracted page images (and cached llm calls) for test_presentation_odp, test_presentation_pptm and test_presentation_pptm have changed.
Reason: converted pdf has pages defined with
/MediaBox[0 0 960.009448818898 540]. We request image with width=800.Before, pdfplumber would read the width as 960.009448818898 in python float type, calculated the scale and called pypdfium2. But pypdfium2 uses C float type, so for pypdfium2 the parsed width would be 960.0094604492188. Using the scale calculated by pdfplumber and rounding up, the resulting width of the image would be 801.
But now we use pypdfium2 directly and do not have this inconsistency - the resulting image width is 800.
The extracted images for the other tests have not changed.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.