Skip to content

Commit

Permalink
toc: adjust code to match pattern of PdfPage.get_objects()
Browse files Browse the repository at this point in the history
  • Loading branch information
mara004 committed Sep 15, 2022
1 parent dac4d6c commit 628b4c3
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/pypdfium2/_helpers/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,6 @@ def get_toc(
:class:`.OutlineItem`: The data of an outline item ("bookmark").
"""

if level >= max_depth:
return []
if seen is None:
seen = set()

Expand All @@ -383,12 +381,13 @@ def get_toc(
seen.add(address)

yield self._get_bookmark(bookmark, level)
yield from self.get_toc(
max_depth = max_depth,
parent = bookmark,
level = level + 1,
seen = seen,
)
if level < max_depth-1:
yield from self.get_toc(
max_depth = max_depth,
parent = bookmark,
level = level + 1,
seen = seen,
)

bookmark = pdfium.FPDFBookmark_GetNextSibling(self.raw, bookmark)

Expand Down

0 comments on commit 628b4c3

Please sign in to comment.