← Back to Pull requests

Change page size without scaling the content (#7116) #7836

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 19, 2026 04:16 UTC
Author

What this changes

Fixes #7116.

Organize pages ▸ Change page size gives pages a new size without scaling anything on them, e.g. an A4 page on an A3 sheet at 100%.

  • Size: a standard paper from the print presets (A0–A6, US Letter/Legal, Tabloid, ARCH, ANSI and the rest) or a custom width and height, portrait or landscape. It's seeded from the current page.

  • Position: one of nine anchors (centred by default), then a move right and down.

  • Pages: all, the current page, or a range. The width, height and move limits follow the chosen pages' /UserUnit. When no size fits every chosen page (e.g. units 1 and 20,000), the dialog says so and turns off the size fields and OK.

  • Preview: shows the first chosen page's new edges around what it showed now. The outline turns red with a note when part of it would be cut off. After OK, a notice counts the pages that lost part of what showed.
  • How it's done (pdfcraft_organize::set_page_size):

  • The media box moves around each page's visible area (its crop box). No content is rewritten or scaled.

  • Sizes are in points as the page is shown, so a turned page (/Rotate) or a /UserUnit page ends up at the size you asked for, with the anchor where you see it.

  • The crop, bleed, trim and art boxes go back to the whole new page. An inherited crop box is overridden.

  • Where the new page reaches past what showed, the content is wrapped in a clip to what showed: two small streams around the page's own streams, which stay as they are. So bleed, marks or anything the old crop box hid stays hidden instead of turning up on the bigger sheet.

  • Text and images added in PdfCraft stay where they're drawn: their stored boxes (display space, from the shown page's corner) move with the page's new corner, so a later move or Replace image keeps them in place. An item whose stream another page also draws gets its own copy on the resized page first, so the other page's box doesn't move.

  • Every page is checked before any changes. Bad sizes (1 to 14,400 user units a side), placements, offsets, page numbers and an empty page list are refused, and nothing changes.
  • Headless: page_set_size {doc, pages?, paper | width+height, orientation?, align?, move_right?, move_down?}.

  • paper takes a preset name or a written size like 297x210mm. A written size keeps its order.

  • It returns page_sizes, plus cut_off: the 1-based pages where part of what showed is now outside.

  • The preset lookup doc_print used is now shared, with no change to doc_print.
  • Wiring: the page.size command, Organize menu, Organize panel and All tools entries, dialog=page-size on the control channel, and an undo label ("Change page size").

    How you verified it

    CARGO_TARGET_DIR shared, macOS arm64:

  • cargo fmt --check (organize, engine, automation, ui-egui)

  • cargo clippy --no-deps -p pdfcraft-organize -p pdfcraft-engine -p pdfcraft-automation -p pdfcraft-ui-egui --all-targets -- -D warnings: clean. Without --no-deps, the local clippy (1.99) stops first on a collapsible_match in crates/xfdf/src/xfdf.rs:326, which is already on main and isn't touched here.

  • cargo test -p pdfcraft-organize: 241 passed, including 5 new change_page_size_ tests:

  • - every turn (0/90/180/270, plus -90 and 450) × four placements: the old visible area lands, unscaled, where the placement puts it on the page as shown (read back through pdfcraft_model's view matrix after a save and reopen)
    - /UserUnit sizes and limits
    - cut pages reported, other boxes reset, clip streams written, no clip when shrinking, a 0.004 pt difference not counted as a cut
    - inherited crop box
    - bad requests refused atomically
  • cargo test -p pdfcraft-automation --test it -- changing_page_size tool_table doc_print_takes: the text found by text_find keeps its size and moves exactly by the placement (+100/+100 centred, +10/+20 top-left with a move). Also checked: page_render at the new size, one undo step, a written landscape size, cut_off, and seven refused argument sets plus two refused sizes with the document unchanged.

  • cargo test -p pdfcraft-engine: 788 passed; added_content_stays_put_when_the_page_size_changes and page_size_change_leaves_a_shared_added_item_on_other_pages_alone (two pages sharing one added image's stream, only page 1 resized: page 2 keeps [10,20,60,70], also after Replace image). The 7 OCR tests that fail here need OCR models and fail the same way without this change.

  • cargo test -p pdfcraft-ui-egui --lib -- pagesize pageboxes (the draft's paper and orientation logic, the size limits per /UserUnit, and that the dialog's preview placement is the engine's) and --test it -- pageboxes:: (the dialog in the real shell: seeded from the page, Landscape, the cut warning, OK, the notice, undo label, reseeding, and the "no page size in common" note with OK off). The 10 OCR/comments/editing it failures here also fail without this change.

  • cargo xtask layers, cargo xtask parity, cargo xtask wasm: clean.
  • This is a new feature, so the new tests can't run on main: the API, edit, command and tool don't exist there.

    Never-crash

  • No new unwrap/expect/panic!/unreachable!/todo! outside tests

  • No input-derived indexing (get), finite and range checks on every size, share and offset, before any page changes

  • No unsafe

  • No crash fixed here
  • Provenance

  • No asset added (the dialog uses the existing Lucide maximize-2 icon)

  • No font files

  • No GPL/AGPL code

  • Behaviour from ISO 32000-2 (§14.11.2 page boxes, §7.7.3.3 /Rotate, §8.5.4 clipping, Annex C page limits) and the issue. Acrobat's own Change Page Size was not observed for this.

  • No new assets, so ATTRIBUTION.toml is unchanged
  • Security

  • --root untouched (no file paths in the new tool)

  • MCP and the control channel unchanged apart from one more dialog name

  • No network access
  • Parity and reach

  • organize.change-page-size goes from planned to shipped, with evidence and notes on what is still missing: scaling the content to fit the new size (#2821), and comments outside what showed aren't hidden by the clip

  • Reachable headlessly through page_set_size

  • No documented behaviour changed
  • Anything a reviewer should look at first

  • The clip. When the new page reaches past the old visible area, the page's content is clipped to that area, so content the old crop box (or the page edge) hid doesn't appear. That's the "same page on a bigger sheet" reading of #7116. The alternative, showing everything the bigger page now covers, would silently reveal cropped-away content. Comments aren't clipped. Content with more Q than q can pop the clip early.

  • The other boxes reset to the new page rather than keeping their old rectangles. A trim box left at the old A4 size inside a new A3 page would tell a printer to cut it back to A4.

  • Cut detection and the clip ignore less than 0.01 pt (converted through /UserUnit), so a page "resized" to its own preset size (595.276 vs 595.28) isn't reported as cut.
  • <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    Added a Change Page Size option in the Pages menu and Organize panel. Apply standard paper sizes or custom dimensions, with portrait or landscape orientation, to the current page, a page range, or all pages.
    Choose from nine placement anchors and set offsets; existing content is not scaled. Preview and results indicate when visible content may be cut off.
    * Added page-size changes to automation, including standard or custom dimensions and page selection.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: mansur-akhmadi Review duration: 17630m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.52) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #7836"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.7% · Safe to merge
    29.7%