Skip to content

BUG: Use the page top for a named destination instead of a fixed value - #4099

Merged
stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:named-destination-page-top
Sep 17, 2026
Merged

stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:named-destination-page-top

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

add_named_destination builds its destination array with a hardcoded /FitH top
of 826, whatever the page actually measures:

ArrayObject([page_ref, NameObject(TypFitArguments.FIT_H), NumberObject(826)])

826 appears exactly once in the codebase and matches no page size. On US Letter
(792 units tall) it points 34 units above the top of the page, so the viewer
scrolls past the content instead of to it; on anything smaller the gap is
larger.

Per §12.3.2.2 the top operand of /FitH is the vertical coordinate positioned at
the top edge of the window, so it now reads the page's own mediabox top. Using
.top rather than the height also keeps it correct for a mediabox whose origin is
not at zero.

The existing test asserted /D[0] (the page reference) but never /D[2], which is
why the value went unnoticed; the new test covers Letter, A4, a small page and
an offset origin.

This is separate from #3522: that asks for a customisable fit type, which you
noted needs an API design since each fit takes different parameters. This only
corrects the top value of the existing /FitH behaviour.

Offline suite passes, 1367 tests.

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

@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.09%. Comparing base (ca60531) to head (cde13d2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4099   +/-   ##
=======================================
  Coverage   98.09%   98.09%           
=======================================
  Files          59       59           
  Lines       11521    11523    +2     
  Branches     2151     2151           
=======================================
+ Hits        11302    11304    +2     
  Misses        125      125           
  Partials       94       94           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stefan6419846
stefan6419846 merged commit d970841 into py-pdf:main Sep 17, 2026
46 of 48 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