Tag Archive for 'hplip'

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.

Installing Cups remote administration and HP OfficeJet with CentOS

This relates to installing an Office Jet with hplip for uses on a print server.  A good Linux server can operate for weeks, months, and even longer without reboots.  hp-setup -i configures the printer.  This may not work over pure SSH console-only.  It will work with X over SSH via Xming by launching gnome-terminal and then running hp-setup -i in that terminal. The Cups web administration panel works via cupsctl –remote-admin. The firewall needs to allow traffic on port 631 via firewall-cmd –zone=public –add-port=631/tcp –permanent, and then firewall-cmd –reload. Command firewall-cmd –list-all shows the active ruleset.   Cups administration website works at http://10.10.10.10:631, replacing the IP address with the one for the Linux server.  Windows uses the print via network printer with address of the form http://10.10.10.10:631/printers/Officejet-4630-series, where the IP address is the machine with Cups remote access, and where the printer name is the actual one on the server.   The printer name appears in the Cups administration website.

Other notes: Best Practices for the Linux and Application Admins – Great article with mistakes and the lessons learned, Running a program as root on startup [creating a service for use with systemd] – excellent discussion on creating services.  Keeping SSH access secure – Basic analysis on dealing with SSH worms that try many username and password combinations. This page on Microsoft’s DevOps for bots has a lot of useful resources such as telemetry, testing, dashboards, and source examples related to bots and smart agents.