Repository navigation
Conversation
PageLayout._get_image, which annotate() uses when a page has neither an image nor an image path, rendered every page of the PDF to PNG and then opened one. Pass the page as first_page/last_page so only that page is rendered. Getting one page of a 400-page PDF drops from 16-20s to under 0.1s, and the temporary PNGs from about 165 MiB to a single page. Page numbers below 1 index from the end of the document, so those still render every page. A page past the end still raises the same ValueError. Rendered pixels, size and rotation metadata match the previous output for every page number from -n-1 to n+1 on the sample PDFs and on a mixed-rotation document. Co-authored-by: wtfyd-agent[bot] <328989958+wtfyd-agent[bot]@users.noreply.github.com>
This was referenced Oct 24, 2026
Contributor
Author
|
Combined effect of #530, #531, #532 and #533 merged together onto
|
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.
Summary
PageLayout._get_imagehotloads a page image forannotate()when the page has neither an image nor an image path. It rendered every page of the PDF to PNG in a temp dir and then opened one of them, so its cost grew with document length. It now passes the page toconvert_pdf_to_imageasfirst_page/last_page, so only that page is rendered.Impact
sample-docs/pdf2image-memory-error-test-400p.pdf, one call:Behavior preserved
image_paths[page_number - 1]); page 0 returns the last page, whichtest_get_imagerelies on. Those still render every page.ValueError.pdf_rotation,pdf_rotation_correction) match the previous output for every page number from −n−1 to n+1. Checked onrotated-page-90.pdf,loremipsum_multipage.pdf,empty-document.pdf,layout-parser-paper.pdf,form-field.pdf, and a generated 5-page document with pages rotated 0/180/90/270/90. That covers rotation corrections that are looked up by page index when only part of the document is rendered.Verification
test_unstructured_inference/inference/test_layout.py:main)ValueErrormake test: 386 passed, 1 skipped.ruff check/ruff format --checkclean.No overlap with #524, which adds pre-rendered
image_pathstofrom_file/process_file_with_modeland doesn't touch_get_image. Version bumped to 1.6.17 with a CHANGELOG entry; #530–#532 also target 1.6.17, so later merges need the next patch version.