DarkenMyPDF

How to clean up a scanned PDF

6 min read

Cleaning a scan means removing everything on the page that is not the document: the paper's colour, the shadow of the phone, the dust on the platen, the ghost of the text on the other side of the sheet.

Done well, it makes the page easier to read, cheaper to print and smaller to store. Done carelessly, it takes the pencil annotations with it.

The four kinds of dirt

  • Colour cast. The paper is beige, grey or blue-tinted, and the whole page is printed with that wash.
  • Uneven illumination. A gradient across the page — bright centre, dark corners — typical of phone scans and thick books.
  • Speckle. Isolated dark pixels from dust, scanner noise or heavy compression.
  • Show-through. Faint text from the reverse of a thin sheet, visible because the scanner lit the page from behind as well as in front.

Background normalisation handles the first two

Estimate the paper level in a grid across the page — take the lightest values in each cell, which is by definition the paper — smooth that grid so it carries no text structure, then divide each pixel by its local paper level.

Casts and gradients both disappear, because both are properties of the estimated background rather than of the content. What remains is the ink, sitting on a consistent white.

Despeckling without damaging text

A median filter replaces each pixel with the middle value of its neighbours, which removes isolated specks very effectively. Applied to the whole page it also rounds the corners of small text and thins hairlines.

The fix is to apply it only where the page is already close to paper white. Specks sitting on the background are removed; anything on the ink side of the histogram is not touched at all. Dust goes, the text does not change.

Show-through, and its limits

Show-through is usually much lighter than the real text, so raising the background level pushes it into the white along with the paper.

Where the reverse side was printed heavily — a dark image, bold headings — show-through can be as dark as faint real text, and no amount of tone adjustment separates them reliably. At that point, rescanning with a black backing sheet behind the page is the real fix.

Cleaning usually shrinks the file

A noisy grey background is expensive to compress: every speck is high-frequency detail the encoder has to store. Flatten it to uniform white and there is almost nothing left to encode.

That is why a cleaned scan is often smaller than the original, even after being re-rendered at print resolution.

Know what you are willing to lose

Background whitening cannot tell the difference between a stain and a pencil note — both are only slightly darker than the paper. If a document contains faint annotations you need, use a lower background setting and accept a slightly greyer page.

Questions

Can cleaning remove a watermark?

A light grey watermark often disappears along with the background, because that is what background whitening does. It is a side effect, not a feature, and it should not be used to strip markings from documents you do not own.

My cleaned scan lost some light pencil marks.

Lower the Background slider. Pencil sits very close to paper in lightness, so it lives right on the boundary the cleaner is drawing.

Try it on your own file

Everything described above runs in your browser — nothing is uploaded.