Skip to content

Ignore only the outline whose named destination is not defined - #129

Merged
0xabu merged 2 commits into
0xabu:mainfrom
RavSinghChandan:outline-missing-named-destination
Nov 12, 2026
Merged

0xabu merged 2 commits into
0xabu:mainfrom
RavSinghChandan:outline-missing-named-destination

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

When an outline refers to a named destination that the document doesn't define, doc.get_dest() raises PDFDestinationNotFound inside the loop in _get_outlines(). process_file() catches it and logs

WARNING: Failed to retrieve outlines: b'_TableParagraph71_MS.F0'

but by then the generator has stopped, so every outline after that one is lost too, and annotations in those sections get no heading.

I found it with 2017.pdf from pypdf's test files (132 pages): it has 530 outlines, 10 of which name a destination that isn't defined, and pdfannots keeps only the first 70.

_get_outlines() now catches PDFDestinationNotFound for that one outline, logs a warning naming it, and goes on with the next one. On 2017.pdf it keeps 520 outlines.

tests/missing-named-destination.pdf is a small hand-written file with three outlines, the second of which names a destination that isn't in /Dests. The MissingNamedDestination tests check that Chapter 1 and Chapter 3 are kept and that one warning names Chapter 2; both fail on main. pytest tests.py, mypy ., flake8 and autopep8 --diff pass.

Used Claude (Opus) to help find and patch this; I reviewed and tested the change

RavSinghChandan and others added 2 commits November 10, 2026 13:54
One such outline stopped the outline loop, so every later outline was
dropped too (460 of 530 in a real report).
@0xabu
0xabu merged commit 0c555d8 into 0xabu:main Nov 12, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants