Skip to content

Instantly share code, notes, and snippets.

@pmbuko
Last active December 25, 2015 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmbuko/7044657 to your computer and use it in GitHub Desktop.
Save pmbuko/7044657 to your computer and use it in GitHub Desktop.
Prints a pdf as postscript to an lpr queue. Requires pdf2ps. (http://yourmacguy.wordpress.com/2009/08/18/print-pdfs-as-postscript-to-an-lpr-queue/)
#!/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment