--- /dev/null
+#!/bin/sh -e
+
+name="$1"
+[ -n "$name" ] || {
+ echo "Usage: $0 <output.pdf>"
+ exit 1
+}
+name=$(readlink -f "$name")
+
+D=`mktemp -d`
+cd "$D"
+echo "Output file directory: $D"
+PAGE=0
+while true; do
+ PAGE=$((PAGE+1))
+ scanimage --resolution 150 --mode Gray -x 210 -y 297 | convert -rotate 180 -modulate 120 -level 30,60% - cur.png
+ FNAME=page`printf '%02i' $PAGE`
+ pngquant 4 < cur.png > $FNAME.png
+ convert $FNAME.png $FNAME.pdf
+ echo "Insert next page and press Enter; q to stop"
+ read x
+ [ "$x" = q ] && break || true
+done
+
+pdfjoin --outfile "$name" page*.pdf
+
+#rm -rf "$D"