Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -x
- set -e
- target="${1}.pdf"
- num_pages=${num_pages:-1}
- if [[ -z "$target" ]]; then
- echo >&2 "Usage: $0 DESTINATION"
- exit 1
- fi
- echo "Scanning $num_pages page(s) to $target..."
- tempdir=$(mktemp -d)
- scansource=$(LC_ALL=C scanimage -L \
- | grep 'HP 7650 Document scanner' \
- | sed "s,^device \`\([^']\+\)'.*,\1,")
- (
- cd "$tempdir"
- scanimage -d"$scansource" -B64 --format=tiff -l0 -t0 -x215 -y297 \
- --batch-start=0 \
- --batch-count="$num_pages" \
- --batch-increment=1 \
- -b \
- --mode Color \
- --resolution 300 \
- --source ADF
- )
- convert="convert ${tempdir}/out0.tif"
- convert "${tempdir}/out0.tif" "${tempdir}/out0.pdf"
- gs="gs \
- -dBATCH \
- -q \
- -dNOPAUSE \
- -sDEVICE=pdfwrite \
- -sOutputFile=- \
- ${tempdir}/out0.pdf"
- for ((i=1; i < num_pages; ++i)) do
- convert "${tempdir}/out${i}.tif" "${tempdir}/out${i}.pdf"
- convert="$convert -append ${tempdir}/out${i}.tif"
- gs="$gs ${tempdir}/out${i}.pdf"
- done
- $convert "${tempdir}/scanimage.pnm"
- gocr -i "${tempdir}/scanimage.pnm" -o "${tempdir}/${1}.txt" -f UTF8
- a2ps -Xutf-8 -i "${tempdir}/${1}.txt" -o "${tempdir}/${1}.ps"
- $gs "${tempdir}/${1}.ps" > "$target"
- ls -lh "$tempdir"
- ls -lh "$target"
- rm -r "$tempdir"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement