Published at
Updated at
Reading time

I live in Germany, and while many think we have things in order here, we still need to sort out bureaucracy. It's a clu**fu** at best because German officials rely on paper – paper and handwritten signatures.

It can go so far that a scanned document image is preferred over a nice and sharp PDF. I don't own a printer, let alone a scanner, so occasionally, I drag myself to the local copy shop to do official business.

Until now! I've been browsing Hacker News, and the shell script below takes a PDF and makes it look like it's been scanned.

ROTATION=$(shuf -n 1 -e '-' '')$(shuf -n 1 -e $(seq 0.05 .5))

convert -density 150 $1 \
  -linear-stretch '1.5%x2%' \
  -rotate ${ROTATION} \
  -attenuate '0.01' \
  +noise  Multiplicative \
  -colorspace 'gray' $2

Suppose you called the script, you can now run the following command...

./ original.pdf scanned.pdf

... to scan your PDFs without a physical scanner.

Examples showing how digital scanned documents could look like.

Side note: the convert command is part of the imagemagick tools and wasn't available on my machine. You might have to install it first. A brew install imagemagick did the trick for me, though.

Was this snippet helpful?
Yes? Cool! You might want to check out Web Weekly for more snippets. The last edition went out 4 days ago.
Stefan standing in the park in front of a green background

About Stefan Judis

Frontend nerd with over ten years of experience, freelance dev, "Today I Learned" blogger, conference speaker, and Open Source maintainer.

Related Topics

Related Articles