Get rid of the black edges on a scanned PDF
Every page of the scan has a thick black band round it. Sometimes down one side, sometimes all four. The document in the middle is perfectly readable — it is just sitting inside a black picture frame, and printing it lays solid toner over most of the sheet.
Nothing is wrong with the file. It is not damage and it is not corruption. The black is a photograph of the inside of your scanner. Once you know that, taking it off takes two minutes, and you can stop it happening to the next batch.
Why the frame is there
A scanner does not photograph your page. It shines a light up through the glass and measures how much comes back. Paper returns most of it, so paper reads as white. Where there is nothing above the glass, the light carries on into the room, nothing returns, and a sensor reading no light writes black.
So a black frame means the scanner spent part of its pass looking at something that was not your page. Three usual ways that happens:
The lid was open, or could not close flat. The underside of a scanner lid is white for exactly this reason — it is what reflects light back over the glass your page does not cover. Leave it up, or rest it on something thick, and the uncovered glass is looking at the ceiling.
The page was smaller than the scan area. An A5 sheet or a receipt captured at full A4 leaves a wide strip of bare glass in the scan. With the lid down that strip comes back white. With the lid up, or on a machine with a dark backing, it comes back black.
The backing is black on purpose. Many document scanners and sheet feeders use a black backing plate so the driver can find the edge of the paper by contrast and crop to it automatically. Switch that detection off, or feed a sheet skewed enough to defeat it, and you get the backing plate instead — usually a band along one edge.
Books are the fourth case and the worst, because a spine will not lie flat. The unlit gap between page and glass comes out as a dark smear down the gutter, and everything past the edges of the book is open air. Do the black edges first if you are also dealing with two book pages on every PDF page: a clean sheet makes the halving measurement much easier to get right.
Measure the border once
Cropping wants millimetres off each side, so you need four numbers — and only once, because every page off the same machine has the same frame.
Print one page at 100% and put a ruler on it, or watch the pointer position in your reader's status bar as you move it to the edge of the paper. Failing both, work it out from the page size: our PDF inspector reads every page's width and height in points without uploading anything, and points divided by 2.835 are millimetres.
Measure the four sides separately, because they are almost never equal. On a flatbed the sheet is pushed into one corner against two registration edges, so those two sides come out clean and the other two carry nearly all the black. Then take a millimetre or two less than you measured: under-cropping costs a second pass, over-cropping means starting again from the original.
Trim it off every page
- Open Crop PDF, upload the scan, and leave "pages to crop" on all — one machine, one pass, one frame.
- Put your four measurements into top, bottom, left and right. The sides are named as you see them on screen, so a page stored sideways still trims the edge you are pointing at.
- Open the result on the busiest page you have — a table that runs wide, a footnote at the very foot. That is where a trim a millimetre too keen shows up.
- Still a sliver of black down one side? Run the output through again with just that one number. Trims come off the current window, so a second pass adds to the first.
When the band is a wedge, not a stripe
If the black is 2 mm thick at the top of the page and 12 mm at the bottom, the sheet went through crooked and no straight trim will square it up. Straighten first, then measure, then crop.
Deskew PDF measures the tilt of the text lines on each page and turns the page back to level. Know the price: a page it corrects is redrawn as a picture, so any text layer on it is lost and the file grows. Pages that were already straight are copied across untouched — and on a raw scan there is no text layer to lose, which is why this order is the cheap one.
It will not rescue a photo of a document taken at an angle. That is perspective, not tilt, and no rotation makes the near edge and the far edge the same length.
Toner yes, megabytes no
The toner is saved. Printers print the crop box, so once the frame is outside it the printer stops laying black down. The exception is worth knowing: a handful of older programs ignore the crop box and print the full sheet regardless, so if a colleague reports the border is back, that is why.
The megabytes are not saved. The scan is one image object per page and the crop box does not cut it up, so every black pixel is still in there, just outside the frame — and those pixels are not cheap. A black border is not flat black. It is thousands of slightly different very dark values, because a sensor reading almost no light is mostly reading its own noise, and noise is the one thing image compression cannot throw away.
Re-encoding the images is what shrinks it, and a scan gives back more than most files do. Compress PDF at the default 150 dpi rescues most email attachments, and if the scan is in colour but the original was black type on white paper, tick "turn pictures grey" while you are there — on that kind of file it is the biggest single saving available.
Use that box rather than our Greyscale PDF tool, which is meant for print shops and would make this file larger. What a compressor can actually reach covers both, and why a document that is not a scan often has nothing to give at all. If a colour charge on a print job is the real problem, that has its own answer.
Crop before OCR, not after
The frame does real damage to recognition. An engine starts by deciding where the ink is and by estimating the page's skew, and it does both from the whole image. A solid dark band drags the threshold about so faint type near the edge drops out, and the border itself gets read as a column of characters — which is why an uncropped scan so often produces a margin of garbage down one side.
Most recognition pipelines render the page before reading it, and rendering respects the crop box, so a crop is enough for them. Anything that pulls the embedded image straight out of the file will still see the border, and there the pixels have to be gone rather than hidden.
Before you upload anything: our OCR PDF tool reports rather than recognises. There is no Tesseract on this deployment, so nothing in your file changes and no text layer appears — you get a page-by-page account and that is all. Useful for finding the scanned sheets in a mixed bundle, which is a job of its own, and no substitute for recognition. We would rather say so here than afterwards.
When a desktop tool does it properly
If the black has to be gone rather than hidden, or you are doing this every week, stop using a browser for it.
- unpaper was written for this exact problem: it finds and
wipes dark scanner borders, deskews and despeckles, on the pixels themselves. Run it over a PDF
through OCRmyPDF —
ocrmypdf --clean-final --deskew in.pdf out.pdfcleans the edges, straightens the pages, keeps the cleaned image and adds the text layer we cannot. - ScanTailor Advanced is the book-scanning workbench: content detection, edge cleanup, spread splitting and margins, with a preview at each stage.
- ImageMagick, when you just want the pixels shaved off:
magick -density 300 in.pdf -shave 40x40 out.pdf. It rasterises the document, so check the resolution you asked for is the one you wanted.
Stopping it at the scanner
Five minutes in the driver beats all of the above, because it means there is nothing to crop next time.
- Close the lid. It is the cause more often than everything else combined. For a thick book, lay a sheet of white paper over the exposed glass instead.
- Turn on automatic size detection — "Auto detect", "Crop to original", "Detect size", depending on the make. This is what the black backing plate is there for.
- Look for "edge fill" or "border removal". Document-scanner drivers from Fujitsu, Canon and Kofax paint a few millimetres of white round every scan, before the file exists.
- Set the paper size explicitly when auto-detection keeps failing. An A5 sheet scanned as A5 has no spare glass to photograph.
The border was never part of your document. Everything above either hides it, removes it, or stops the scanner recording it — and only the last of those is a job you do once.