PdfWriter.add_named_destination() does not maintain the name tree sort order #1927
Labels
is-bug
From a users perspective, this is a bug - a violation of the expected behavior with a compliant PDF
needs-example-code
The issue needs a minimal and complete (e.g. all imports) example showing the problem
needs-pdf
The issue needs a PDF file to show the problem
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 versionsThe text was updated successfully, but these errors were encountered: