Straighten a crooked scanned PDF
Deskewing means measuring the slight tilt a scanner or document feeder gave each page and rotating the page image back until the text lines run level. This page finds each page's tilt by testing rotations up to 4 degrees in either direction and picking the angle at which horizontal rows of pixels alternate most sharply between dark text bands and light gaps — the row-projection variance method. Pages tilted less than 0.3 degrees are left untouched, every corrected page is re-rendered straightened, and the tool reports the exact correction angle applied to each page. All processing happens in your browser.
How it works
The measurement relies on a simple property of printed text: on a perfectly level page, a line of text is a dark horizontal band and the leading between lines is a light one. If you sum the darkness of every pixel in each horizontal row — a row projection — a level page produces a sharply oscillating profile: high sums where the text lines are, near-zero sums in the gaps. Tilt the page even one degree and each pixel row now cuts diagonally through several text lines at once, smearing the profile into a bland middle gray with weak peaks.
That gives an objective score for "how level is this page": the statistical variance of the row sums. Straight pages have high variance (extreme dark rows and extreme light rows), skewed pages have low variance (everything averaged out). The tool renders each page with pdf.js, downsamples it to grayscale for speed, and evaluates that variance at a series of candidate rotation angles between −4° and +4°, narrowing in on the peak — first coarsely, then in fine steps around the best coarse result. The angle that maximizes the variance is the negative of the page's skew, and each page is measured independently, because a document feeder rarely tilts two sheets identically.
Correction is applied only when it pays for itself. Re-rendering a rotated bitmap resamples every pixel, which costs a small amount of sharpness, so pages measured under 0.3° are passed through untouched — a tilt that small is below what a reader notices. Pages over the threshold are re-rendered at the corrected angle onto a clean white canvas of the original page dimensions and reassembled into a new PDF with pdf-lib. When the run finishes, the tool lists the correction applied to every page (for example, "page 4: −1.7°, page 5: straight"), so you can verify the result page by page.
Because output pages are images, deskewing pairs naturally with the rest of the scan workflow: rotate any sideways pages first with Auto-rotate scans (deskew handles fine tilt, not 90° turns), then deskew, then run OCR — recognition accuracy improves measurably once lines are level.
Illustrative example: a 20-page feeder scan
Illustrative scenario, not a recorded benchmark. File sizes, timings and results depend on the input and device. Try the reproducible samples.
A 20-page contract went through an office document feeder that was pulling slightly to the left, producing a 4.8 MB PDF where most pages lean between 1 and 2 degrees — enough that every paragraph visibly runs downhill and highlighted rows in tables drift across ruled lines. The tool measures and corrects all 20 pages in roughly 30 seconds on a mid-range laptop.
The per-page report reads: 14 pages corrected between −0.8° and −2.1°, 2 pages corrected at +0.4° and +0.6° (sheets that fed at a slight opposite angle), and 4 pages reported as straight because they measured under the 0.3° threshold and were passed through unchanged. The output file is 5.0 MB — marginally larger than the input because the re-rendered pages are freshly encoded — and every text line now sits level against the table rules. A follow-up OCR pass on the straightened file recognized the same pages with visibly fewer errors than a test pass on the tilted original, particularly in the tables, where a 2° lean had been placing cell text on the wrong row.
Frequently asked questions
How do I straighten a crooked scanned PDF?
Use a deskew tool: it measures each page's tilt angle from the geometry of the text lines and rotates the page image by the opposite angle. This page does it automatically in your browser — each page is analyzed, corrected up to plus or minus 4 degrees, and re-rendered level, with the applied angle reported per page.
How does the tool know what angle the page is tilted at?
It tests candidate rotations and, for each one, sums the pixel darkness of every horizontal row. When text lines are perfectly level, dark rows (lines of text) alternate sharply with light rows (the gaps between lines), which maximizes the variance of those row sums. The candidate angle with the highest variance is the page's true skew.
Why were some of my pages left unchanged?
Pages measured at less than 0.3 degrees of tilt are deliberately skipped — a rotation that small is invisible in normal reading, and re-rendering it would cost a little sharpness for no visible gain. The per-page report marks these pages as already straight.
What is the maximum tilt this tool can fix?
It searches up to 4 degrees in either direction, which covers virtually all feeder and flatbed misalignment. A page scanned wildly off-angle or sideways is a rotation problem rather than a skew problem — fix those with a page-rotation tool first, then deskew the remainder.
Does deskewing work on pages with photos and little text?
It is most reliable on pages dominated by lines of text, because the row-band pattern is what the measurement locks onto. A page that is mostly one photograph gives a weak signal, and the tool may find no confident angle and leave that page as is.
Will I still be able to select text after deskewing?
No — corrected pages are re-rendered as images, so any text layer is not preserved. Scanned PDFs usually have no text layer anyway; if you need a searchable result, deskew first and then run OCR, which will read the straightened lines more accurately.