New Tool Radar

AI PDF

How to Check Page Skew and Rotation in a Scanned PDF Before Running OCR

Preview each scanned page for tilt and wrong-way-up rotation, then let OCRmyPDF deskew and rotate the pages before recognition.

Schematic with three steps: Preview the pages and note skew and; Run OCRmyPDF with deskew and rotation detection; Check the corrected pages before trusting the.

A page scanned at a slight angle, or upside down, confuses the recognizer: lines of text run diagonally and characters are read in the wrong order. Checking skew and rotation before OCR, and correcting them first, saves a run that would produce garbage text.

What you need

  • OCRmyPDF installed
  • A scanned PDF
  • A terminal
  • A PDF viewer to preview pages

Step 1: Preview the pages and note skew and rotation

Open the PDF and look at several pages. Note any page where the text lines tilt, and any page that is sideways or upside down.

Step 2: Run OCRmyPDF with deskew and rotation detection

Run OCRmyPDF with –deskew to straighten tilted pages and –rotate-pages to detect and correct rotated pages, and let it write a corrected PDF.

Step 3: Check the corrected pages before trusting the text

Open the corrected PDF and confirm the text lines are horizontal and the pages are the right way up, then run OCR on the corrected file.

Worked example: synthetic skew check on a 20-page scan

The table below is a synthetic example. It shows the expected result of the skew review; no review was run.

Page Problem Correction
Page 2 Tilted about 2 degrees Deskew
Page 7 Upside down Rotate 180 degrees
Page 12 Straight None
Total 20 pages 2 pages to correct

Expected result (UNTESTED). page 2 needs deskewing and page 7 needs rotating, while the rest are straight, so the corrected file is ready for OCR. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • Deskew works on pages with clear text lines; a page of handwriting or a diagram may not deskew correctly.
  • Rotation detection can mistake a landscape table for a rotated page, so check the result.
  • Correcting skew and rotation changes the page image, so keep the original scan until the OCR output is verified.

Sources

See all