Tag Archive for 'pdf'

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
FILEOUTPUT="/home/${USERNAME}/Scans/$1-scanned-${YMD}.pdf"
hp-scan --adf --mode=color &&
PART=hpscan
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 ${LATESTSCAN}
rm -f "/home/username/Temp/$1-uncompressed-scanned-${YMD}.pdf"
killall evince

Compressing PDFs in Bash

I have scripts for hplip to scan PDF’s to folders using the ADF. These PDFs are very large. To convert these to smaller file-sizes for emailing, I added the following functions to .bashrc.

mediumpdf() { read -p "Enter input PDF filename: " name \
&& gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/printer -sOutputFile=medium-quality-$name $name; }
smallpdf() { read -p "Enter input PDF filename: " name \
&& gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/ebook -sOutputFile=low-quality-$name $name; }
tinypdf() { read -p "Enter input PDF filename: " name \
&& gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/screen -sOutputFile=lowest-quality-$name $name; }
bestpdf() { read -p "Enter input PDF filename: " name \
&& gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/prepress -sOutputFile=best-quality-$name $name; }

Using a 32.9MB test PDF straight from HPLIP, bestpdf created a 10.5MB with very good quality that was almost indistinguishable from the original.  Mediumpdf created a 7.8MB that looked good enough for faxing with some color distortion.  Smallpdf created a 1.5MB that might be good enough for faxing.  Tinypdf created a 482kB with clear color distortions.