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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Save the script to a location in your path (/usr/local/bin works) and you’re off.