Crop Rotated PDF Pages Without Trimming the Wrong Edge

Last updated

Crop PDF reads the rotation of every page first, so on rotated PDF pages the Top margin still trims the edge you see at the top.

Pages turned by 90, 180 or 270 degrees get cropped by their visible edges. A page with any other angle stops the crop with an "Unsupported page rotation" error.

Crop PDF

How Crop PDF Maps Margins on Rotated PDF Pages

A PDF page is rotated in multiples of 90 degrees. PDFPage reference (pdf-lib docs)

PDF page coordinates start at the lower left corner of the page media box. Coordinate systems (Acrobat SDK reference)

On a page turned 90 degrees clockwise, the edge you see at the top is the left side of the stored page, so Crop PDF moves your Top value over there.

On a page turned 180 degrees each margin swaps with its opposite. Top trims the stored bottom, and Left the stored right.

Width and height swap as well, so on a 90 or 270 degree page the Left and Right values count against the width you see.

Crop PDF margin fields Top, Right, Bottom and Left in points, the fields used to crop rotated PDF pages; this screenshot has 72 in Bottom, our test put 72 in Top

Our Test: One Upright and One Turned Page

We cropped a two page A4 file with Top set to 72 and the other margins at 0. Page 1 was stored upright; page 2 was stored with a rotation of 90 degrees.

Page 1 lost 72 points at its stored top edge and came out 595 by 770 points.

On page 2 the new crop box starts 72 points in from the stored left edge, which is the edge a viewer shows at the top. The page stays landscape at 842 by 523 points.

Turned Only in Your Viewer: Why the Wrong Edge Goes

Crop PDF reads the rotation saved in the file, not the view in your reader, so a page you only turned on screen still counts as upright.

Turn page 1 of our test file a quarter turn clockwise in a reader, and the trimmed stored top shows up on the right side instead of the top you meant.

Rotate PDF saves the turn as the page's rotation value, exactly what page 2 of our test carried. After that, the Top margin trims the edge you see on top.

Rotate the pages with Rotate PDF before cropping if they face the wrong way, then enter margins for the upright view.

PDFs That Mix Upright and Turned Pages

Each page gets mapped on its own, so a PDF that mixes upright and rotated pages gets the same visible margins on all of them.

Open the cropped file and check one upright and one turned page before you share it.

Continue with Does Cropping a PDF Remove Content? No, It Only Hides It or Crop PDF Margins Do Not Fit on Page: Causes and Fixes.

Frequently Asked Questions about Crop Rotated PDF Pages Without Trimming the Wrong Edge

Why did a crop seem to trim the wrong side of my page?

Save the rotation into the file with Rotate PDF first, since a view turned only in your reader stays upright in the file.

Does cropping change the page orientation?

No. The rotation value of every page stays exactly as it was before the crop.

Which page angles does Crop PDF handle?

Upright pages and pages turned 90, 180 or 270 degrees. Other angles return an error.

Should I rotate before or after cropping?

Rotate first, then crop, so you set the margins while looking at the upright page.