Skip to content

Commit

Permalink
Update _writer.py - Invalid Link Fix py-pdf#2448
Browse files Browse the repository at this point in the history
passes an IndirectObject for the target page instead of an integer. passing an integer creates an invalid link.
resolves py-pdf#2443 Issue
  • Loading branch information
rsinger417 committed Feb 8, 2024
1 parent 3fb63f7 commit 1596d06
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pypdf/_writer.py
Expand Up @@ -2129,17 +2129,18 @@ def add_annotation(
# destination
if to_add.get("/Subtype") == "/Link" and "/Dest" in to_add:
tmp = cast(Dict[Any, Any], to_add[NameObject("/Dest")])
# Changes target_page_index a integer to target_page an IndirectObject
page.annotations.append(self._add_object(to_add))
target_page = pages_obj[PA.KIDS][tmp["target_page_index"]]
pages_obj = cast(Dict[str, Any], self.get_object(self._pages))
dest = Destination(
NameObject("/LinkName"),
tmp["target_page_index"],
target_page,
Fit(
fit_type=tmp["fit"], fit_args=dict(tmp)["fit_args"]
), # I have no clue why this dict-hack is necessary
)
to_add[NameObject("/Dest")] = dest.dest_array

page.annotations.append(self._add_object(to_add))

if to_add.get("/Subtype") == "/Popup" and NameObject("/Parent") in to_add:
cast(DictionaryObject, to_add["/Parent"].get_object())[
NameObject("/Popup")
Expand Down

0 comments on commit 1596d06

Please sign in to comment.