How to straighten a crooked scanned PDF

Fix scanned pages that came out tilted. How automatic deskew measures the angle, when to set it by hand, and why to straighten before you run OCR.

Scan & OCRBy the EddiesPDF teamUpdated 5 min read
Open Deskew PDF

A sheet went into the feeder at a slight angle, or the page shifted on the scanner glass as you closed the lid, and now every line of text runs gently uphill. It's readable. It also looks careless, and it makes OCR noticeably worse.

Straightening a scan, usually called deskewing, means measuring how far each page is tilted and turning it back by the same amount. Deskew PDF does that in your browser, page by page, without uploading the file.

How the tilt is measured

The method is simple enough to explain in a couple of paragraphs.

For each page, the tool renders a temporary image (up to about 1,400 pixels on the long side) and decides which pixels are ink and which are paper. The cut-off is worked out from that page's own mix of light and dark, so grey recycled paper or a faint scan doesn't throw it off. Then it tries a series of angles. For each one, it imagines the page turned by that much and counts how many ink pixels fall on every horizontal row.

On a level page of text, those counts are spiky. Rows that pass through a line of text are full of ink, and the gaps between lines are nearly empty. Tilt the page and each line of text smears across several rows, so the spikes flatten out. The angle that gives the sharpest pattern is the one that makes the text level.

It checks from -15 to +15 degrees in half-degree steps, then narrows in around the best result in steps of 0.05 degrees. Only that measurement uses the temporary image. The page itself is never converted to a picture.

Two safety checks stop it from "fixing" pages that are fine. A tilt smaller than 0.15 degrees is ignored, since you can't see it anyway. And the best angle has to give a clearly sharper pattern than leaving the page alone; if it doesn't, the page is left untouched.

What gets rotated, and what doesn't

When a page needs correcting, the tool wraps the page's existing content in a rotation around the centre of the page. Whatever was on the page (the scanned image, plus any text layer from earlier OCR) turns together and stays aligned. Text that was selectable stays selectable, and the file size barely changes.

The page itself doesn't change size. That has two visible side effects on a full-page scan:

  • The edges of the scanned image are now at a slight angle, so you may see thin empty wedges along the borders.
  • The very corners of the image can be pushed just past the edge of the page and cut off. At one or two degrees that's a few millimetres of scanner background, not content.

If the wedges bother you, trim the margins afterwards with Crop PDF.

Comments, highlights, form fields and links sit in a separate layer on top of the page and aren't rotated. If you're going to annotate a scan, straighten it first.

Straightening a scan step by step

  1. Open Deskew PDF and drop in the scanned PDF.
  2. Leave "Mode" on "Automatic".
  3. If only some pages are crooked, open "More options", choose "Custom" under "Pages" and type a range such as 1-3, 7.
  4. Click "Straighten pages". A progress line shows which page is being measured.
  5. Read the results and download the file, saved as deskewed- plus the original name.

The results screen lists what changed, for example "Straightened 3 of 12 page(s): page 2 (+1.25°), page 5 (-0.80°), page 9 (+2.10°)". If none needed it, you get "No crooked pages found" and nothing on the pages is changed.

There's also a checkbox in More options: "Only straighten strongly skewed pages". With it ticked, only pages tilted by more than 0.70 degrees are corrected. I'd use it on long documents where most pages are fine and you'd rather not touch anything that doesn't obviously need it.

When automatic detection gets it wrong

The measuring trick depends on rows of text. Pages without them give it nothing to work with:

  • Photos, diagrams and drawings with few straight lines of text.
  • Nearly blank pages. Very little ink means no measurement, and the page is skipped.
  • Very dark pages, such as a photo that fills the page. If most of the page counts as ink, it's skipped too.
  • Text that was set at an angle on purpose, like a rotated table heading or a diagonal stamp, which can pull the result off.

For those, switch "Mode" to "Manual angle". You type an angle between -45 and 45 degrees, or nudge it with the -1, -0.5, -0.1, +0.1, +0.5 and +1 buttons. Positive numbers turn the content counter-clockwise. The thumbnails below rotate as you change the number, so you can match it by eye before committing. Combine it with a custom page range to fix a single stubborn page and leave the rest alone.

Automatic mode only looks for tilts up to 15 degrees. Anything beyond that is a page that went in badly wrong, and Manual angle is the way to fix it. A page that's sideways or upside down isn't skewed, it's rotated by a whole quarter turn, and Rotate PDF is the tool for that; see the guide to rotating PDF pages.

What deskewing can't fix

Rotation only fixes rotation. If you photographed a document with your phone held at an angle, the page is a trapezoid: wider at the bottom than the top, or the other way round. That's perspective distortion, and no amount of turning makes it rectangular. The scanner built into iPhone Notes and the Google Drive app correct perspective when you scan, so use those rather than the plain camera. The phone scanning guide covers how.

It also can't fix curved lines near the spine of a thick book pressed onto a flatbed, or blur. And there's nothing to gain from running it on a PDF exported from Word or a web page: those were never tilted.

Do it before OCR, not after

If you're going to make the scan searchable, straighten it first. Character recognition works best on level text, and a tilt of a degree or two is enough to cost accuracy. Once it's straight, run it through OCR PDF; the guide to making a scanned PDF searchable goes through the settings.

A sensible order for a fresh batch of scans is: straighten, crop, OCR, then compress. Each step works on the cleaner output of the one before.

Try Deskew PDF
Free, no sign-up, and it works on your phone too.
Open Deskew PDF

Also useful: OCR PDF · Crop PDF

More guides