Skip to content

Add EagerlyLoadImageBytes parsing option#1280

Closed
EdwardBlair wants to merge 4 commits intoUglyToad:masterfrom
EdwardBlair:feature/lazy-image-bytes
Closed

Add EagerlyLoadImageBytes parsing option#1280
EdwardBlair wants to merge 4 commits intoUglyToad:masterfrom
EdwardBlair:feature/lazy-image-bytes

Conversation

@EdwardBlair
Copy link
Copy Markdown

@EdwardBlair EdwardBlair commented Apr 15, 2026

Adds a ParsingOptions.EagerlyLoadImageBytes flag (defaults to true so nothing changes for existing users). When set to false, image byte data is stripped during page processing but all the metadata like width, height, bounding box, color space etc is still available. This should help with the OOM issues in #1171 where large images blow up memory on low-RAM machines, it does not prevent the image bytes from being read into memory but does flag them for GC.

Also makes XObjectImage.RawMemory lazy so even with the default settings, enumerating images for metadata doesn't force the bytes to be copied around.

This is a stop gap in lieu of a larger change to lazy the stream.

Line endings were mixed so I've normalised them. I will do a separate PR to normalise them across the entire repo as required. Git should handle this transparently.

Warning

Please view this with ?w=1 otherwise you will get spammed with line ending changes
https://github.com/UglyToad/PdfPig/pull/1280/files?w=1

@EdwardBlair EdwardBlair force-pushed the feature/lazy-image-bytes branch from 4bc5f0a to 77b7248 Compare April 15, 2026 16:31
@EdwardBlair EdwardBlair force-pushed the feature/lazy-image-bytes branch 3 times, most recently from 02daebc to f30a16d Compare April 15, 2026 17:04
@EdwardBlair
Copy link
Copy Markdown
Author

See #1281

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.

1 participant