Repository navigation
BUG: Use page reference for existing internal link targets - #4076
Merged
stefan6419846 merged 4 commits intoSep 15, 2026
Merged
Conversation
Closed
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4076 +/- ##
=======================================
Coverage 98.11% 98.12%
=======================================
Files 59 59
Lines 11489 11494 +5
Branches 2150 2151 +1
=======================================
+ Hits 11273 11278 +5
Misses 122 122
Partials 94 94 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
The remaining |
stefan6419846
approved these changes
Sep 15, 2026
stefan6419846
left a comment
Collaborator
There was a problem hiding this comment.
Looks good to me.
stefan6419846
added a commit
that referenced
this pull request
Sep 16, 2026
## What's new ### Security (SEC) - Limit size of alphabetical page labels (#4096) by @stefan6419846 ### Deprecations (DEP) - Replace PdfWriter method add_js (#3979) by @j-t-1 ### Performance Improvements (PI) - Move static value out of loop body for appearance stream data (#4087) by @stefan6419846 - Reduce number of full data lookups for attachment mapping API (#4081) by @stefan6419846 ### Bug Fixes (BUG) - Do not copy unrelated pages when appending pages with non-terminal fields (#4078) by @anandghegde - Use page reference for existing internal link targets (#4076) by @r-kamei - Arabic-Indic digits are reversed during text extraction (#4077) by @Syamjith-NK - Parse a string rect for add_uri into a rectangle (#4074) by @RavSinghChandan [Full Changelog](6.18.1...6.19.0)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This change resolves pypdf's intermediate internal-link destination to the target page's indirect reference when the target page is already present in the writer.
When the target page has not yet been added, the existing page-index representation is preserved.
Scope
Based on the current code paths, this change is limited to pypdf's intermediate representation of an internal direct destination:
Remote and external links should not be affected. URI links and remote or embedded go-to actions are represented through an
/Aaction dictionary, such as/URI,/GoToR, or/GoToE, rather than through the annotation-level intermediate/Destdictionary handled here.An already completed explicit destination is represented as an array rather than this intermediate dictionary, so it is also left unchanged.
Compatibility
The discussion in #2450 raised the question of whether allowing an internal link to reference a page that has not yet been added to the writer should be treated as supported behavior or as a bug.
This PR intentionally does not make that decision. If the target page is not yet present in the writer, the existing page-index representation is preserved. The change only resolves the destination to an
IndirectObjectwhen the target page is already available.The remaining behavior for targets added later can therefore be discussed and addressed separately without blocking this limited improvement.
Tests
The added tests verify that:
IndirectObject;AI usage
I used Microsoft 365 Copilot, based on the GPT-5 reasoning model, to assist with reviewing the code paths related to direct
/Destentries and remote link actions. I reviewed and verified the resulting implementation and tests myself.