Skip to content

Instantly share code, notes, and snippets.

@hron84
Created July 28, 2013 00:07
Show Gist options
  • Save hron84/6096805 to your computer and use it in GitHub Desktop.
Save hron84/6096805 to your computer and use it in GitHub Desktop.
#!/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