Created
July 28, 2013 00:07
-
-
Save hron84/6096805 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PAPEROPTS="-x 210mm -y 297mm" | |
SCANOPTS="${PAPEROPTS} --resolution 300 --format=tiff --mode Gray" | |
function die() { | |
echo " !!!! $@ !!!!" | |
exit 1 | |
} | |
function scan_page() { | |
count=$(( ${count} + 1)) | |
local n=$(printf "${template}" ${count}) | |
echo "Scanning page ${count} into '${n}'..." | |
scanimage $SCANOPTS > "${n}.tiff" || die "Scanning error $?" | |
convert "${n}.tiff" "${n}.pdf" | |
rm "${n}.tiff" | |
echo "${n}.pdf" >> scanlist.$$ | |
} | |
read -p "Image prefix [contract]: " prefix | |
if [ -z "${prefix}" ]; then | |
prefix="contract" | |
fi | |
template="${prefix}_%02d" | |
count=0 | |
echo -n "Select paper source [ADF/flat]: " | |
read src | |
if [ "${src}" != "flat" ]; then | |
SCANOPTS="--source ADF ${SCANOPTS}" | |
fi | |
echo "Press ENTER to start scanning" | |
read || exit 0 | |
while true; do | |
scan_page | |
echo "Press ENTER to scan next page, 'q' to end scanning" | |
read key | |
if [ "${key}" = "q" ]; then | |
break | |
fi | |
done | |
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="${prefix}.pdf" $(cat scanlist.$$) | |
rm -f scanlist.$$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment