Does straightening a scanned PDF make the text unselectable?
You have a scan that someone already put through OCR. The text selects, the search box finds things, and the whole document sits three degrees off level, so every page looks like it is sliding off the screen.
Straightening it is a two-click job on any number of websites. None of them say what happens to the text you can currently select, and you have a reasonable suspicion that it is about to disappear.
It is, on some of the pages. Which ones is predictable, and the order you do things in decides whether you end up with a level document you can search or a level document you cannot.
The short answer
Yes for every page the tool actually corrects. No for every page it leaves alone. There is no middle ground and no partial version: a corrected page loses one hundred per cent of its text layer, not the parts that moved.
That sounds worse than it is, because most straightening tools — ours included — only redraw the pages that need redrawing. Deskew PDF measures each page in the range you give it, and if the tilt comes out under a tenth of a degree it copies the original page across byte for byte: text layer, links, annotations, colour, sharpness, everything. A page it turns by 2.4° is redrawn as a picture. So the real question is not "will this remove my text layer" but "which of my pages are crooked enough to be redrawn", and you can answer that before you upload anything.
Why straightening has to redraw the page
A scanned page is one instruction: draw this photograph here. The words are pixels inside the photograph. Turning the page level means turning the photograph, and turning a bitmap is not free — every pixel in the output lands between four pixels of the input and has to be blended out of them. The result is a new picture. There is no way to rotate a grid of pixels onto a different grid and still have the original grid.
The text layer of an OCR'd scan is a separate thing sitting on top: invisible glyphs positioned over the ink so that a reader can select words it never actually drew. In principle a tool could rotate the image placement and the invisible text with the same matrix and keep both. In practice almost nobody does, ours included, because the angle is measured on the rendered page and the simplest correct output is the rendered page. Everything that was not part of the rendering — the invisible text, the link rectangles, the form fields, the comments — is not carried over.
Worth knowing how the measurement works, because it explains a couple of the odd results. The page is squashed onto its vertical axis and the ink is counted row by row. When the lines are level, rows are either dense with ink or empty and the counts swing wildly; tilt the page and every line smears across several rows and the counts flatten. The angle with the most variation is the angle your text is really sitting at. It is measured on a reduced copy about 1,100 pixels down its long edge, which means raising the resolution does not make the angle more accurate — it only decides how sharp, and how heavy, the redrawn pages come out.
Work out which pages are at risk first
Two minutes here saves the whole question.
- Check whether there is a text layer at all. If the document is a raw scan with nothing behind the ink, you have nothing to lose and can stop reading. Our PDF inspector reads that out of the file in the browser without uploading it. If the text does not select, work out why before you assume it is a scan — a locked file and a photograph look identical from the outside and only one of them needs OCR.
- Find out which pages carry real text. Run OCR PDF and read it backwards from its usual purpose: the list of pages that already have a text layer is exactly the list of pages that have something to lose. The caveat further down says where that tool stops being useful.
- Look at which pages are visibly crooked. Usually it is the scanned exhibits at the back, not the typed report at the front.
- Set the page range to the overlap of "crooked" and nothing else. On a mixed document, naming pages 40-56 rather than leaving it at all is the whole difference. Every page you leave out is copied across untouched.
- Leave the angle range at 10 degrees. A sheet fed through a scanner is rarely more than two or three degrees out. Widening the search does not make a measurement more accurate; it gives a wrong one more room to be wrong by a larger amount.
The order that keeps you both things
If the scan has not been recognised yet: straighten first, recognise second. Tilt costs a recogniser real accuracy, and the text layer it writes is laid out in horizontal rows over ink that is not horizontal — which is why selection highlights on a crooked OCR'd scan tend to drift off the words as you go down the page. Straighten, then recognise, and the boxes sit where the words are. Why the order matters as much as it does, and what else belongs in the sequence, is its own answer.
If the scan has already been recognised and is still crooked, you are choosing. Either live with the tilt and keep the searchable text, or straighten and have it recognised again. For an archive somebody paid to have recognised, the second option means paying twice.
What else a corrected page gives up
The text layer gets the attention, but the redraw takes four other things with it. All of them apply only to the pages actually turned.
- Colour. Corrected pages are rendered in greyscale. A red stamp, a highlighted clause or a blue signature comes back grey. If that matters, this tool is not the one.
- Links, comments and form fields. They were never part of the rendering. A filled form that gets straightened is a picture of a filled form.
- Anything outside the crop box. Cropping in a PDF hides a margin rather than deleting it, so a cropped page still carries the full sheet. Rendering makes the crop permanent. That is occasionally the point — it is a tidy way to make a Crop PDF stick — but it is one-way.
- The corners. The turned page is drawn back onto a sheet the same size, so the corners swing off the edge. At two degrees on A4 that is roughly 5 mm at the left and right and 3.5 mm at the top and bottom, replaced with white. Ordinary margins swallow it. Content running to the very edge does not.
And the file gets bigger, because a picture of a page costs more bytes than the instructions for drawing one. Running the result through Compress PDF gets most of it back — a redrawn page is a greyscale image, which is the one thing compression is genuinely good at, though not every file has anything left to give.
Two things straightening is not
It is not rotation. Ninety or a hundred and eighty degrees out is a page stored sideways, which is a metadata change that costs you nothing. Use Rotate PDF for that, and run it before you deskew.
It cannot fix a photograph taken at an angle. In a phone photo the page is a trapezium, not a tilted rectangle, and no rotation can make the near edge and the far edge the same length. Rescan it flat, or use a phone scanning app that lets you drag the four corners.
One more: it needs something text-shaped to measure. A page that is mostly a plan, a photograph or a signature has no line structure in it, so the measurement comes back near zero and the page is left alone — which at least means it keeps everything it had. The opposite failure is worth watching for too. A page dense with ruled lines, a table or a form gives the profile something that looks exactly like text lines but is not, and can be measured wrongly. Check the notes: a page reported as turned by nine degrees deserves a look before you keep the result.
When a command line is genuinely the better tool
If the document needs to end up both straight and searchable, do not do this in a browser at all.
OCRmyPDF is the honest answer: ocrmypdf --deskew in.pdf out.pdf
levels each page and recognises the levelled version, so you finish with a straight document whose
text layer fits it. That is precisely what our OCR tool cannot do. The rest of that pipeline — the
resolution to set, the steps worth skipping, the tool for a stack of a hundred scans — is set out
alongside the ordering question.
For a single sheet, magick in.png -deskew 40% out.png is ImageMagick, and it is the cheapest way to
see what a correction does to one image before trusting it with two hundred.
The browser tools win when you have one crooked file, no text layer worth protecting, and no wish to install anything.
After it is straight
Two things usually remain on a scan that has just been levelled. The white wedges the rotation left along the edges can come off with Crop PDF, and if there is a black band there instead of white, that is the scanner lid and it has its own short answer.
Then compare a corrected page against the original at full size before you delete anything. The notes tell you what was turned and by how much; only your eyes will tell you whether the trade was worth it.