High Quality compressed HPLIP scans

HPLIP produces scans far better than what I can accomplish on Windows, even with Adobe Acrobat Standard.  The Auto Document Feeder scans in 8.3 megapixel png files, and then hplip converts them to a multiple-page PDF of extremely high quality.  This is great for one page documents, but for 10 or 12 page documents, such as faxes, the file size becomes a problem due to email limitations.  Ghostscript can compress these.  This creates several steps unless the process is simplified.  To that end, here is a shell script that scans from the ADF using HPLIP and compresses the PDF output to the prepress/best setting, as mentioned in the article on Compressing PDFs in Bash.

This assumes that there is a ~/Temp directory, and a ~/Scans directory for scans to go in.  Additionally, the username must be replaced in the script a few places.  The CP command refused to inflate the ${USERNAME} variable, and so it has to be coded into the script.

#!/usr/bin/env bash
YMD=$(date +"%Y-%m-%d")
#  Create a folder, ~/Temp and create a folder, ~/Scans
hp-scan --adf --mode=color &&
LATESTSCAN=`ls -t ${PART}*pdf | sed "1q"`
echo "${LATESTSCAN} ready for ${FILEOUTPUT}"
#  Why you shouldn't parse the output of ls
#  http://mywiki.wooledge.org/ParsingLs 
#  This does not use the FILEOUTPUT variable itself because the cp command
#  seems to have trouble copying the file correctly, even with switches. 
#  Change the 'username' without braces to the the actual username.
cp ${LATESTSCAN} "/home/username/Temp/$1-uncompressed-scanned-${YMD}.pdf"
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/prepress \
-sOutputFile="/home/username/Scans/$1-scanned-${YMD}.pdf" ${LATESTSCAN}
sleep 1
rm -f "/home/username/Temp/$1-uncompressed-scanned-${YMD}.pdf"
killall evince

Leave a Reply