Skip to content

Lazy loading for images #3822

Description

@stefan6419846

Explanation

Loading images should be done lazily in the ImageFile class instead of on creating the ImageFile class. Relevant derivable values (width, height and data size) should be queried from the stream header without reading the actual stream to allow users to impose limits on which image streams should be loaded.

Code Example

from pypdf import PdfReader

reader = PdfReader("file.pdf")
for page in reader.pages:
    for name in page.images.keys():
        image = page.images[name]
        if image.width > 5000 or image.data_size > 1_000_000:
            continue
        image.image.save(name)

Metadata

Metadata

Assignees

No one assigned

    Labels

    is-featureA feature requestworkflow-imagesFrom a users perspective, image handling is the affected feature/workflow

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions