Skip to content

Commit 7883580

Browse files
authored
BUG: Process CMYK images without a filter correctly (#2557)
Closes #2522
1 parent 42f970e commit 7883580

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

pypdf/filters.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,16 @@ def _xobj_to_image(x_object_obj: Dict[str, Any]) -> Tuple[Optional[str], bytes,
817817
".tiff",
818818
False,
819819
)
820+
elif mode == "CMYK":
821+
img, image_format, extension, invert_color = (
822+
Image.frombytes(mode, size, data),
823+
"TIFF",
824+
".tif",
825+
False,
826+
)
827+
elif mode == "":
828+
raise PdfReadError(f"ColorSpace field not found in {x_object_obj}")
820829
else:
821-
if mode == "":
822-
raise PdfReadError(f"ColorSpace field not found in {x_object_obj}")
823830
img, image_format, extension, invert_color = (
824831
Image.frombytes(mode, size, data),
825832
"PNG",

tests/test_images.py

+9
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,12 @@ def test_bi_in_text():
246246
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
247247
assert reader.pages[0].images.keys() == ["~0~"]
248248
assert reader.pages[0].images[0].name == "~0~.png"
249+
250+
251+
@pytest.mark.enable_socket()
252+
def test_cmyk_no_filter():
253+
"""Cf #2522"""
254+
url = "https://github.com/py-pdf/pypdf/files/14614887/out3.pdf"
255+
name = "iss2522.pdf"
256+
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
257+
reader.pages[0].images[0].image

0 commit comments

Comments
 (0)