Published at
Updated at
Reading time
1min

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.

#!/bin/sh
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 index.sh, you can now run the following command...

./index.sh 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.

If you enjoyed this article...

Join 5.4k readers and learn something new every week with Web Weekly.

Web Weekly — Your friendly Web Dev newsletter
Reply to this post and share your thoughts via good old email.
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