New Tool Radar

OCR & Text Layers

How to Auto-Rotate Sideways Pages Before OCR with OCRmyPDF

Let OCRmyPDF detect and correct sideways pages before recognition, and check the text comes out upright.

Schematic illustration of OCRmyPDF page rotation: without it the sideways page is garbled, with --rotate-pages it reads upright.

OCRmyPDF’s manual says –rotate-pages automatically rotates pages based on detected text orientation, and that –rotate-pages-threshold sets the confidence needed before a page is rotated.

Use the practice file

A practice document, practice-sideways.pdf. The file is fictional.

Page Content
1 Upright page, 8 lines
2 Sideways page, rotated 90 degrees, including the word “harvest”
3 Upside-down page, rotated 180 degrees

Page 2 is the check page: the word “harvest” appears there once, on a sideways page.

Check auto-rotation

Expected result. We checked the OCRmyPDF manual and the Tesseract manual. We did not run any tool. The checks below are what to expect if the work is done correctly; run them yourself on the practice file.

1. Run OCR without rotation

Run ocrmypdf practice-sideways.pdf out1.pdf and copy page 2.

Expected result: The sideways page produces garbled or missing text.

2. Run OCR with –rotate-pages

Run ocrmypdf –rotate-pages practice-sideways.pdf out2.pdf.

Expected result: OCRmyPDF detects the orientation and rotates the pages.

3. Select the word

In out2.pdf, drag across “harvest” on page 2.

Expected result: “harvest” highlights exactly, on an upright page.

4. Check the upside-down page

Copy page 3 of out2.pdf.

Expected result: Page 3 also reads upright, with its text in order.

Verdict table

Check Expected result Pass?
Run OCR without rotation The sideways page produces garbled or missing text. —
Run OCR with –rotate-pages OCRmyPDF detects the orientation and rotates the pages. —
Select the word “harvest” highlights exactly, on an upright page. —
Check the upside-down page Page 3 also reads upright, with its text in order. —

Related guides: How to Batch OCR a Multi-Page PDF with Consistent Settings — How to Add a Searchable Text Layer to a Scanned PDF.

Limits

  • Auto-rotation needs enough text to detect orientation: a page with one line may not rotate, so check each page rather than trusting the batch.
  • Command-line OCR rewrites the file, so always work on a copy and keep the original scan untouched.
  • UNTESTED — no OCR tool was run; all results above are expected results. The practice file is fictional.

Sources

See all