Skip to content

Fix normalizeRotation page size retrieval#522

Open
shunyy wants to merge 1 commit intoembedpdf:mainfrom
shunyy:fix/normalize-rotation-page-size
Open

Fix normalizeRotation page size retrieval#522
shunyy wants to merge 1 commit intoembedpdf:mainfrom
shunyy:fix/normalize-rotation-page-size

Conversation

@shunyy
Copy link
Contributor

@shunyy shunyy commented Mar 11, 2026

fix #521

Summary

Replace EPDF_GetPageSizeByIndexNormalized with FPDF_GetPageSizeByIndexF + application-side dimension swap for normalizeRotation mode.

Problem

Page dimensions were incorrectly retrieved for certain PDFs when opened with normalizeRotation: true.

Root Cause

EPDF_GetPageSizeByIndexNormalized was designed to be lightweight by reading MediaBox/CropBox directly from the page dictionary via
dict->GetRectFor() without constructing a CPDF_Page. However, this does not resolve PDF page tree attribute inheritance.

Affected PDFs

  • PDFs with MediaBox defined on parent /Pages node -- when the page dictionary lacks its own /MediaBox, the fallback 612x792 (US Letter) is
    used instead of the inherited value
  • PDFs with CropBox inherited from the page tree -- similarly fails to retrieve the correct CropBox

Construction_plan_partial_render_demo.pdf
H21_OilPan.pdf

…ormalized

EPDF_GetPageSizeByIndexNormalized reads MediaBox/CropBox directly from the
page dictionary without resolving page tree inheritance, which produces
incorrect dimensions for PDFs where these boxes are inherited from parent
/Pages nodes.

Replace with FPDF_GetPageSizeByIndexF (which correctly resolves inheritance
via CPDF_Page) and swap width/height in the application layer for 90°/270°
rotated pages when normalizeRotation is enabled.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@vercel
Copy link

vercel bot commented Mar 11, 2026

@shunyy is attempting to deploy a commit to the OpenBook Team on Vercel.

A member of the Team first needs to authorize it.

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.

Large-format PDF pages render only partially (A0/architectural plans)

1 participant