Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image extraction raises "ValueError: illegal image mode" #2030

Closed
stefan6419846 opened this issue Jul 27, 2023 · 1 comment · Fixed by #2039
Closed

Image extraction raises "ValueError: illegal image mode" #2030

stefan6419846 opened this issue Jul 27, 2023 · 1 comment · Fixed by #2039

Comments

@stefan6419846
Copy link
Collaborator

I am trying to extract the images from a PDF file, which fails with "illegal image mode"

Environment

Which environment were you using when you encountered the problem?

$ python -m platform
Linux-5.14.21-150400.24.69-default-x86_64-with-glibc2.31

$ python -c "import pypdf;print(pypdf.__version__)"
3.13.0

Code + PDF

This is a minimal, complete example that shows the issue:

from pypdf import PdfReader

reader = PdfReader('redacted.pdf')
for page in reader.pages:
    for image in reader.images:
        print(image)

I have generated a mostly empty version of the document reproducing this issue: redacted.pdf

Traceback

This is the complete traceback I see:

Traceback (most recent call last):
  File "/home/stefan/temp/analyze.py", line 17, in <module>
    for image in page.images:
  File "/home/stefan/temp/pypdf/pypdf/_page.py", line 2604, in __iter__
    yield self[i]
  File "/home/stefan/temp/pypdf/pypdf/_page.py", line 2600, in __getitem__
    return self.get_function(lst[index])
  File "/home/stefan/temp/pypdf/pypdf/_page.py", line 522, in _get_image
    imgd = _xobj_to_image(cast(DictionaryObject, xobjs[id]))
  File "/home/stefan/temp/pypdf/pypdf/filters.py", line 892, in _xobj_to_image
    img, image_format, extension = _handle_flate(
  File "/home/stefan/temp/pypdf/pypdf/filters.py", line 804, in _handle_flate
    img.putpalette(lookup.get_data())
  File "/home/stefan/temp/venv/lib64/python3.9/site-packages/PIL/Image.py", line 1914, in putpalette
    raise ValueError("illegal image mode")
ValueError: illegal image mode
@pubpub-zz
Copy link
Collaborator

for complementary test :
tt

pubpub-zz added a commit to pubpub-zz/pypdf that referenced this issue Jul 29, 2023
MartinThoma pushed a commit that referenced this issue Jul 30, 2023
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 a pull request may close this issue.

2 participants