Skip to content

Commit 96ba79c

Browse files
ROB: Fix compression issues for removed images which might be None (#3246)
Closes #3237.
1 parent 7cff6e0 commit 96ba79c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pypdf/_writer.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1650,8 +1650,9 @@ def replace_in_obj(
16501650
orphans = [True] * len(self._objects)
16511651
# look for similar objects
16521652
for idx, obj in enumerate(self._objects):
1653-
if obj is None:
1653+
if is_null_or_none(obj):
16541654
continue
1655+
assert obj is not None # mypy: TypeGuard of `is_null_or_none` does not help here.
16551656
assert isinstance(obj.indirect_reference, IndirectObject)
16561657
h = obj.hash_value()
16571658
if remove_identicals and h in self._idnum_hash:

tests/test_writer.py

+7
Original file line numberDiff line numberDiff line change
@@ -2668,3 +2668,10 @@ def test_incremental_read():
26682668
# 2 = Pages, 5 = New Page, 6 = XRef, Size == 7
26692669
# XRef is created on write and not counted
26702670
assert len(writer._objects) == 5
2671+
2672+
2673+
def test_compress_identical_objects__after_remove_images():
2674+
"""Test for #3237"""
2675+
writer = PdfWriter(clone_from=RESOURCE_ROOT / "AutoCad_Diagram.pdf")
2676+
writer.remove_images()
2677+
writer.compress_identical_objects(remove_identicals=True, remove_orphans=True)

0 commit comments

Comments
 (0)