[sane-devel] Script for ADF scanning
Raman Gupta
rocketraman at fastmail.fm
Wed May 6 19:01:25 UTC 2009
I wrote this little quick-and-dirty script for ADF scanning to a single
PDF. Would anyone be interested in including this, in some similar form,
in the sane distribution or documentation?
=================================================
#!/bin/sh
OUTPUT=scan.pdf
RESOLUTION=300
MODE=Lineart
SCRIPT=/usr/local/bin/scan_perpage
DUPLEX=0
DESKEW=1
MAXPAGE=
# The unpaper processing reduces the file size considerably, so 300 dpi
is selected.
# When not using unpaper (--nodskew) it is recommended to scan at a
lower resolution e.g. 200 dpi.
# Parse command-line options
while [ $# -gt 0 ]; do
case "$1" in
-d|--duplex) DUPLEX=1 ;;
-m|--mode) shift; MODE=$1 ;;
-r|--resolution) shift; RESOLUTION=$1 ;;
-o|--output) shift; OUTPUT=$1 ;;
-e|--max) shift; MAXPAGE=$1 ;;
--nodskew) DESKEW=0 ;;
esac
shift # next option
done
if [ -f "$OUTPUT" ]; then
echo >&2 "Output file $OUTPUT already exists. Aborting."
exit 1
fi
SOURCE=""
if [ $DUPLEX -eq 1 ]; then
SOURCE="--source \"ADF Duplex\""
fi
if [ "$MAXPAGE" != "" ]; then
MAXPAGE="-e $MAXPAGE"
fi
echo >&2 "Scanning..."
#eval scanadf $MAXPAGE -S $SCRIPT --script-wait --resolution
$RESOLUTION --mode $MODE $SOURCE -o scan-%04d
eval scanadf $MAXPAGE --resolution $RESOLUTION --mode $MODE $SOURCE -o
scan-%04d
numscans=$(ls scan-[0-9]* | wc -w)
if [ $numscans -gt 0 ]; then
echo "Processing $numscans pages"
if [ $DESKEW -eq 1 ]; then
unpaper -v --dpi $RESOLUTION --no-blackfilter scan-%04d unpaper-%04d
for x in unpaper-[0-9]*; do mv $x scan-${x#unpaper-}; done;
fi
echo ""
echo
"-------------------------------------------------------------------------------"
echo "converting image data to pdf..."
for x in scan-[0-9]*; do pnmtops -imagewidth 8.5 -imageheight 11 $x |
ps2pdf - > ${x%.*}.pdf; done;
echo "concatenating pdfs..."
pdftk $(ls scan-[0-9]*.pdf) cat output $OUTPUT
rm scan-[0-9]*
chown raman:raman $OUTPUT
echo ""
echo "Done."
else
echo "Found no scans."
fi
=================================================
More information about the sane-devel
mailing list