stichl.at tech at work

27Nov/120

Bash-script to scan and combine a multipage-PDF in b/w with low filesize

This script scans multiple pages and combines the pages into one pdf-document with size-optimization

Commandline-tools needed:

scanimage
pnmtotiff
tiffcp
tiff2pdf
pdfopt

#!/bin/bash
RESOLUTION=300
DEVICENAME=hp:/dev/scanner
# find your device name using scanimage -L
cd /tmp
scanimage -d $DEVICENAME --resolution=$RESOLUTION --page-width=210 --page-height=297 --batch=out%d.pnm --batch-start=100
ls out*.pnm | while read p; do q=`echo $p | sed 's/out\(.*\)\.pnm/tiff\1.tif/'`; cat $p | pnmtotiff -g4 > $q; done
rm out*.pnm
tiffcp -a -c g4 tiff*.tif out.tif
rm tiff*.tif
tiff2pdf -p "A4" -f -x $RESOLUTION -y $RESOLUTION -c "stichl.at" -s "http://www.seteq.at/" -t "Scanned Document" out.tif > out.pdf
rm out.tif
pdfopt out.pdf output.pdf
rm out.pdf
mv output.pdf ~/scan.pdf
Filed under: Linux Leave comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.