#!/bin/sh
#===========================================================================#
#                 Utility for scanning from scanners with ADF               #
#===========================================================================#
#  Denis Smirnov <ds@seiros.ru>								   26 Aug 2007  #
#===========================================================================#
set +e
DPI=300
HEIGHT=292

D=`date -I`
T=`date +'%H:%M:%S'`
P=~/Desktop/Scans/$D/$T
mkdir -p $P
cd $P
scanimage --resolution $DPI -y $HEIGHT -b --batch-scan=yes > /dev/null

echo "  png..." | osd_cat -p bottom -A center -f -misc-fixed-medium-*-*-*-70-*-*-*-*-*-koi8-r

ls -1 *.pnm | sed 's/^out//'| sort -n | while read s; do
	s=out$s
	echo "$s"
#	pnmflip -rotate180 "$s" > tmp.pnm
#	mv -f tmp.pnm "$s"
	convert "$s" "${s%%.pnm}.png"
	pnmtops -dpi $DPI "$s" >> tmp.ps
	rm -f "$s"
done

echo "  pdf..." | osd_cat -p bottom -A center -f -misc-fixed-medium-*-*-*-70-*-*-*-*-*-koi8-r

# Convert to PDF
ps2pdf14 tmp.ps $P.pdf
rm -f tmp.ps

echo " " | osd_cat -p bottom -A center -f -misc-fixed-medium-*-*-*-70-*-*-*-*-*-koi8-r

# Remove directory if nothing scanned
cd ~/
rmdir "$P" 2> /dev/null > /dev/null
