Skip to content

PdfReader - Extract images from specific pages #2535

Description

@FrsECM

Replace this: What happened? What were you trying to achieve?

Environment

Python 3.8
WSL Ubuntu 22.04
Windows11
pypdf 4.1.0

Issue

I generated a very simple pdf with libreoffice-writer :
test_image.pdf

In this pdf, there is two pages, one containing a small text, another containing an image.

I want to extract pdf pages and get the image only in the second page.

The code to reproduce the issue is here :

pdf = PdfReader(pdf_file)
for i,page in enumerate(pdf.pages):
        print(f'--- Extracting page {i}')
        print(page.extract_text())
        print(len(page.images))

The result is bellow :

--- Extracting page 0
Test page 1
1
--- Extracting page 1
1

I expect that on page 0 there is 0 image in order to extract the image only from the second page.
I don't know if it is a normal behaviour.

How to do what i would like to obtain ?
Thanks,
Regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    workflow-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