Skip to content

Commit

Permalink
BUG: Fix missing page for bookmark
Browse files Browse the repository at this point in the history
Closes #968 (caused by #1016)
  • Loading branch information
MartinThoma committed Jun 21, 2022
1 parent 4c9fd44 commit fbe2a0f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
10 changes: 3 additions & 7 deletions PyPDF2/_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,11 +660,6 @@ def add_bookmark(
"""
if self.output is None:
raise RuntimeError(ERR_CLOSED_WRITER)
out_pages = cast(Dict[str, Any], self.output.get_object(self.output._pages))
if len(out_pages["/Kids"]) > 0:
page_ref = out_pages["/Kids"][pagenum]
else:
page_ref = out_pages

action = DictionaryObject()
zoom_args: ZoomArgsType = []
Expand All @@ -673,8 +668,9 @@ def add_bookmark(
zoom_args.append(NumberObject(a))
else:
zoom_args.append(NullObject())
dest = Destination(
NameObject("/" + title + " bookmark"), page_ref, NameObject(fit), *zoom_args

dest = Bookmark(
TextStringObject(title), NumberObject(pagenum), NameObject(fit), *zoom_args
)
dest_array = dest.dest_array
action.update(
Expand Down
4 changes: 1 addition & 3 deletions tests/test_merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def test_merge():

bookmark = merger.add_bookmark("A bookmark", 0)
bm2 = merger.add_bookmark("deeper", 1, parent=bookmark, italic=True, bold=True)
merger.add_bookmark(
"Let's see", merger.pages[2], bm2, (255, 255, 0), True, True, "/FitBV", 12
)
merger.add_bookmark("Let's see", 2, bm2, (255, 255, 0), True, True, "/FitBV", 12)
merger.add_bookmark(
"The XYZ fit", 0, bookmark, (255, 0, 15), True, True, "/XYZ", 10, 20, 3
)
Expand Down

0 comments on commit fbe2a0f

Please sign in to comment.