Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROB: XYZ destination to cope with missing left and top param #2237

Merged
merged 2 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pypdf/generic/_data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1487,16 +1487,20 @@ def __init__(
self[NameObject("/Type")] = typ

# from table 8.2 of the PDF 1.7 reference.
if len(args) == 0:
pass
elif typ == "/XYZ":
if typ == "/XYZ":
if len(args) < 1: # left is missing : should never occur
args.append(NumberObject(0.0))
if len(args) < 2: # top is missing
args.append(NumberObject(0.0))
if len(args) < 3: # zoom is missing
args.append(NumberObject(0.0))
(
self[NameObject(TA.LEFT)],
self[NameObject(TA.TOP)],
self[NameObject("/Zoom")],
) = args
elif len(args) == 0:
pass
elif typ == TF.FIT_R:
(
self[NameObject(TA.LEFT)],
Expand Down
12 changes: 12 additions & 0 deletions tests/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1454,3 +1454,15 @@ def test_issue_140():
b = get_data_from_url(url, name=name)
reader = PdfReader(BytesIO(b))
assert len(reader.pages) == 54


@pytest.mark.enable_socket()
def test_xyz_with_missing_param():
"""Cf #2236"""
url = "https://github.com/py-pdf/pypdf/files/12795356/tt1.pdf"
name = "issue2236.pdf"
reader = PdfReader(BytesIO(get_data_from_url(url, name=name)))
assert reader.outline[0]["/Left"] == 820
assert reader.outline[0]["/Top"] == 0
assert reader.outline[1]["/Left"] == 0
assert reader.outline[0]["/Top"] == 0