Enhance and optimize image extraction functionality#47
Merged
sumitsahoo merged 2 commits intomainfrom Apr 12, 2026
Merged
Conversation
…f named and inline images
…ection functionality
There was a problem hiding this comment.
Pull request overview
This PR refactors the PDF image extraction tool to improve robustness (supporting more PDF.js image representations), reduce memory churn during extraction, and make image selection/download UX clearer.
Changes:
- Adds PDF.js image-handling helpers to extract both named and inline images and paint them reliably to a canvas (RGBA/RGB/ImageBitmap/src).
- Reworks extraction to reuse canvases across images/pages and performs explicit cleanup after each page and at the end.
- Updates the UI selection model (default: none selected; new “Select all” / “Clear” controls) and memoizes total selected size.
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.
This pull request significantly refactors and enhances the PDF image extraction tool in
src/tools/ExtractImages.tsx. The main improvements include more robust image extraction logic, better memory management, and a clearer user interface for selecting images. The extraction process now supports additional PDF.js image types and handles image data more reliably.PDF image extraction improvements:
PdfjsImageDatainterface and helper functions (fetchNamedImage,paintImageToCanvas) to robustly handle various image representations from PDF.js, including support for both named and inline image objects, and correct handling of different pixel formats (RGBA, RGB, ImageBitmap, and src URLs). [1] [2]page.cleanup(). [1] [2] [3]User interface and usability:
useMemo.These changes make the tool more reliable, efficient, and user-friendly.