Skip to content

fix: add support of scanned pdf with broken xref#118

Merged
Allob merged 4 commits intodevelopmentfrom
f/pdf-with-broken-xref
Feb 27, 2026
Merged

fix: add support of scanned pdf with broken xref#118
Allob merged 4 commits intodevelopmentfrom
f/pdf-with-broken-xref

Conversation

@Allob
Copy link
Collaborator

@Allob Allob commented Feb 26, 2026

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:

  1. 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).

  2. 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.

@Allob Allob self-assigned this Feb 26, 2026
adubovik
adubovik previously approved these changes Feb 26, 2026
@Allob Allob merged commit 486d0f3 into development Feb 27, 2026
9 of 10 checks passed
@Allob Allob deleted the f/pdf-with-broken-xref branch February 27, 2026 17:55
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.

The PDF with broken xref table fails with The document is empty

2 participants