Print PDFs as Postscript to an lpr Queue

I wrote a simple script recently for a user who was having trouble getting certain PDFs to print properly from his linux box (Fedora 10). I first suggested that he try converting the pdfs to ps and printing the resulting file. That worked but he found the process a bit tedious. Here’s the script I wrote to take care of the tediousness. It relies on the standard (in Fedora, at least) pdf2ps package. It should be pretty self-explanatory.


#!/bin/bash
# grab first argument as pdf filename and generate ps filename
thePDF=$1
thePS=$(echo $thePDF.ps)
queueName=$2
usage() {
cat<<EOF
Usage: psprint [your pdf] [lpr queue]*"
This command does three things:"
1. Converts the specified pdf file to ps"
2. Prints the ps file to your default lpr queue *(unless you specify another queue)"
3. Deletes the ps file"
EOF
exit 1
}
if [ $# == 0 ]; then
usage
elif [ $# == 1 ]; then
echo "Converting $thePDF …"
pdf2ps "$thePDF" "$thePS"
echo "Sending to default printer …"
lpr "$thePS"
echo "Cleaning up …"
rm "$thePS"
exit 0
elif [ $# == 2 ]; then
echo "Converting $thePDF …"
pdf2ps "$thePDF" "$thePS"
echo "Sending to $2 …"
lpr -P "$queueName" "$thePS"
echo "Cleaning up …"
rm "$thePS"
exit 0
else
usage
fi

view raw

pdf2ps_print.sh

hosted with ❤ by GitHub

Save the script to a location in your path (/usr/local/bin works) and you’re off.