diff --git a/pypdf/_writer.py b/pypdf/_writer.py index fb3049ef0..b02bdee6d 100644 --- a/pypdf/_writer.py +++ b/pypdf/_writer.py @@ -2129,9 +2129,12 @@ 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 an integer to target_page an IndirectObject + pages_obj = cast(Dict[str, Any], self.get_object(self._pages)) + target_page = pages_obj[PA.KIDS][tmp["target_page_index"]] 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