Closed robertkearns closed 1 year ago
I agree this is a bug. Please create a PR and become a active contributor 🙂
@pubpub-zz I love to see that you encourage people to get active as well :heart: It's awesome that you're contributing that much, but on the long run we will need other contributors to ensure pypdf keeps improving :-) Well done :clap:
When a named destination is added via
writer.add_named_destination()
the resulting (name, destination) combo in the named destination list is always pushed to the back of the names list.This will cause anything (annotations, etc.) using those destinations to not work correctly with some pdf viewers as they are relying on the name list being sorted in lexical order (which is required by the spec).
add_named_destination_array()
andadd_named_destination_object()
both insert the new destination at the correct index.PDF Specification
To quote the "Table 36 – Entries in a name tree node dictionary" the part about the
Names
key:Sample Code
Creating a writer and adding 2 named destinations should be sufficient.
I do think the best proof of this however is reading the source code for
PdfWriter.add_named_destination()
.Affected Versions
This issue occurs in
pypdf==3.11.1
and likely many prior versions