Fix upside-down and sideways pages, automatically
Feed a stack of paper into a scanner and the PDF comes out with page 7 upside down and page 12 on its side. Fixing that by hand means finding each one. rotate --auto reads which way the text runs on every page and turns the wrong ones right.
How to do it
pip install "pdfblah[app]"
pdfblah doctor --install # fetches Tesseract, which does the orientation reading
pdfblah rotate scanned.pdf fixed.pdf --auto
fixed 2 of 41 page(s)
page 7: rotated 180
page 12: rotated 270
(too little text to judge: page(s) 33, left alone) -> fixed.pdf
Why it's safe to run on anything
- The fix is lossless. A page is corrected by flipping its rotation flag, the same thing a viewer's rotate button sets. Nothing is re-rendered; the content stays byte-for-byte what it was.
- Confident detections only. A page has to clearly read wrong before it is touched. Pages with too little text to judge (a photo, a blank divider) are left exactly as they are and named in the report.
- Upright documents pass through unchanged. Running it on a healthy file fixes zero pages and says so.
Tips
- This fixes 90/180/270 rotations. A slightly crooked scan (2 degrees of skew) is a different problem: OCR has
--deskewfor that, and Clean scan handles the cosmetics. - Great as the first step of a scan cleanup: rotate, then tidy, then clean, then OCR. All four run in one batch recipe.
- Non-Latin documents: orientation detection uses the same modular data files as OCR (
pdfblah ocr --get-lang osdif it's missing).