-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Description
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.0Code + 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels