Skip to content

Commit

Permalink
ROB: Skip destination page being None in PdfWriter (#2963)
Browse files Browse the repository at this point in the history
Some PDFs happen `dest["/Page"] is None` which causes 

> AttributeError: 'NoneType' object has no attribute 'indirect_reference'

when merging files.
  • Loading branch information
dxsooo authored Nov 23, 2024
1 parent a6dc19f commit 72a8838
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2758,7 +2758,7 @@ def _process_named_dests(dest: Any) -> None:
):
# already exists : should not duplicate it
pass
elif isinstance(dest["/Page"], NullObject):
elif dest["/Page"] is None or isinstance(dest["/Page"], NullObject):
pass
elif isinstance(dest["/Page"], int):
# the page reference is a page number normally not a PDF Reference
Expand Down
10 changes: 10 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2484,6 +2484,16 @@ def test_append_pdf_with_dest_without_page(caplog):
assert len(writer.named_destinations) == 3


@pytest.mark.enable_socket
def test_destination_page_is_none():
"""Tests for #2963"""
url = "https://github.com/user-attachments/files/17879461/3.pdf"
name = "iss2963.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
writer = PdfWriter()
writer.append(reader)


def test_stream_not_closed():
"""Tests for #2905"""
src = RESOURCE_ROOT / "pdflatex-outline.pdf"
Expand Down

0 comments on commit 72a8838

Please sign in to comment.