diff --git a/src/pypdfium2/_helpers/document.py b/src/pypdfium2/_helpers/document.py index 1a77408b9..d1ecf1b81 100644 --- a/src/pypdfium2/_helpers/document.py +++ b/src/pypdfium2/_helpers/document.py @@ -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() @@ -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)