27 February 2008

Printing PDFs

When I posted my screenshot script I thought of a similar script, which also implements functionality I didn't like. The standard CUPS PDF printer prints to a fixed directory (~/PDF in my case) instead of prompting where you'd like to save it. This annoyed me, so I looked around and discovered the PDF driver's configuration file (/etc/cups/cups-pdf.conf if you use Ubuntu like me) has a directive named PostProcessing. If you set PostProcessing to a script's path, it will run the script after printing the PDF, passing it the printed PDF's filename and the name of the user that printed it. I have mine point to a script I wrote that offers similar functionality as the screenshot script, showing a gnome alert with options to open the PDF or move it somewhere else. Again, I don't write my scripts to be used on other machines, so certain things (like the Adobe Reader icon on line 10) probably won't work for you:

#!/bin/bash
pdf=$1
username=$2
action=${3:-"default"}

export DISPLAY=:0.0

case $action in
default)
notify-more -u low -t 10000 -i /opt/Adobe/Reader8/Resource/Icons/32x32/adobe.pdf.png -n "Open" -x "gnome-open \"$pdf\"" -n "Move" -x "$0 \"$pdf\" \"$username\" move" "PDF Printed" "PDF printed to $pdf" -n "Clipboard" -x "echo -n $pdf | xsel -i -b";;

move)
dest=`zenity --file-selection --title "Save PDF" --save --confirm-overwrite`

if [ "$dest" ]; then
mv "$pdf" "$dest"
if [ -e "$dest" ]; then
notify-more -u low -t 5000 -i /usr/share/icons/gnome/32x32/actions/gtk-paste.png "PDF Saved" "PDF saved to $dest" -n "Open" -x "gnome-open \"$dest\"" -n "Clipboard" -x "echo -n $dest | xsel -i -b"
else
notify-more -u high -t 5000 -i /usr/share/icons/gnome/32x32/emblems/stock_mail-priority-high.png "Save Failed" "Unable to move PDF. The original is stored at $pdf"
fi
fi;;
esac

No comments: