Skip to content

Commit

Permalink
BUG: Handle annotations being None on merging (#3111)
Browse files Browse the repository at this point in the history
Closes #3110.
  • Loading branch information
stefan6419846 authored Feb 9, 2025
1 parent 5a50b57 commit 912b50c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2932,14 +2932,16 @@ def _get_cloned_page(

def _insert_filtered_annotations(
self,
annots: Union[IndirectObject, List[DictionaryObject]],
annots: Union[IndirectObject, List[DictionaryObject], None],
page: PageObject,
pages: Dict[int, PageObject],
reader: PdfReader,
) -> List[Destination]:
outlist = ArrayObject()
if isinstance(annots, IndirectObject):
annots = cast("List[Any]", annots.get_object())
if annots is None:
return outlist
for an in annots:
ano = cast("DictionaryObject", an.get_object())
if (
Expand Down
11 changes: 11 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2607,3 +2607,14 @@ def test_inline_image_q_operator_handling(tmp_path):
)
assert png_path.is_file()
assert image_similarity(png_path, expected_png_path) >= 0.99999


def test_insert_filtered_annotations__annotations_are_none():
writer = PdfWriter()
writer.add_blank_page(72, 72)
stream = BytesIO()
writer.write(stream)
reader = PdfReader(stream)
assert writer._insert_filtered_annotations(
annots=None, page=PageObject(), pages={}, reader=reader
) == []

0 comments on commit 912b50c

Please sign in to comment.