Understanding PDF page rotation
A page attribute, not a rewrite.
Why PDF rotation is one number per page, the four legal angles, and what happens to the embedded content when you change it.
Rotation is metadata.
Every PDF page carries a /Rotate entry, an integer that's one of 0, 90, 180, or 270. The viewer reads that number and rotates the page when displaying. The underlying content stream — the actual drawing instructions — doesn't change. Rotating a page is a one-property edit on the page dictionary; the file size barely moves, the render comes out the right way up.
Only those four angles.
The PDF spec allows only 0/90/180/270 in the /Rotate field. Arbitrary angles (45°, 30°, etc.) aren't supported as page rotation — you'd need to rewrite the content stream with a rotation transform applied to every drawing instruction. That's possible but expensive, and very few real-world workflows want it. The four right-angle increments cover the actual use cases (scanned page upside down, single landscape page in a portrait document).
Why scanned pages are often wrong.
The most common reason to rotate: a multi-page scanner fed a stack and some pages went in upside down or sideways. The scanner produced a PDF with the right page-image content but the wrong rotation metadata. Rotation fixes it in one attribute edit per page. OCR-aware scanners often auto-detect orientation from text direction and set rotation correctly; cheaper scanners don't.
A worked example.
A 50-page document where pages 17, 18, 19 came out sideways. The processor reads the page tree, finds pages 17-19, sets their /Rotate to 90 (or 270, depending on which way they need to flip), writes the file back. Three integers changed; the rest of the file is bit-for-bit identical. Viewers re-rendering the PDF show those three pages the right way up.
Selective rotation
pages 17–19 → /Rotate 90
One property change per page; content stream untouched.
page.setRotation(90) on 3 pages of 50
= File mostly unchanged
Rotation vs flipping.
Rotation is around the page centre; flipping is a mirror across one axis. PDF rotation only does the former. To flip a page (mirror image), you'd need to rewrite the content stream with a scaling transform (scale Y by -1 to flip vertical). Most tools don't expose this because the use case is rare; when it comes up, it's usually a scanning error best fixed at the scanner.
Rotation and annotations.
Annotations (sticky notes, highlights, form fields) have their own rotation handling — they can move with the page rotation or stay fixed. Most PDF libraries do this correctly by default; the trap is when annotations were authored against a different rotation than the current one. The visual result is a sticky note that appears in the wrong location after rotation. Rare in practice but worth checking if you rotate a heavily-annotated PDF.