Correct MediaBox and CropBox sizes and fix #1330#1340
Merged
Conversation
This was referenced Jun 25, 2026
This was referenced Jul 3, 2026
This was referenced Jul 10, 2026
This was referenced Jul 20, 2026
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.
Tidy up and correct MediaBox and CropBox sizes and fix #1330
Breaking change:
Page.MediaBox/Page.CropBoxnow use document (unrotated) coordinatesPage.MediaBox.BoundsandPage.CropBox.Boundsnow return the rectangles exactly as defined in the PDF, in unrotated default user space (ISO 32000‑2 §14.11.2), instead of rectangles that were pre‑rotated and shifted to the origin. The crop box is also now clipped to the media box.Unchanged:
Page.Width,Page.Height,Page.Size, andPage.Lettersbehave exactly as before.This only affects rotated or cropped/offset pages. For a normal page (crop box = media box, at the origin, no rotation) the values are identical, so most code needs no change.
How to adapt
page.Width/page.Height→ nothing to do; they still return the visible (rotation‑applied) size in points.The old clipping was
initialMatrix.Transform(cropBox.Bounds).Normalise(). Since the initial matrix is built from this same crop box, it maps the crop box to the origin and applies the rotation, yielding(0, 0, displayedWidth, displayedHeight), precisely whatGetVisibleBounds()returns directly. So the clipping path is identical for all rotations and crop offsets (verified by the rotated/cropped visual-verification and clipping tests).