- Copy the included script (in the main body of the hint) to /usr/libexec/cups/backend/pdf
- Make it executable by everyone:
% sudo chmod a+x /usr/libexec/cups/backend/pdf
- (Optional) If you have the Acrobat Distiller PPD, put a copy in /usr/share/cups/model
- Restart the CUPS daemon, so it finds your new backend and model (sudo killall -HUP cupsd)
[robg adds: This script has only been tested under Panther. If someone tests it under 10.2 and it works, please post a comment and I'll remove the "10.3:" designation.]
Hold down Option and click on the Add button. In the top list, select Advanced. For Device: choose PDF Writing. Give it a descriptive name (e.g., PDF Writer). For the device URI, use pdf://pathname, where pathname is where you would like the PDF file to be saved -- /tmp is a good choice as it gets cleaned out automatically when you restart. For the printer model, select Adobe (if you installed the Distiller PPD in step three above), otherwise leave it as Generic. Click on Add and you are ready to go!
The script creates a log file (/tmp/pdf.log) each time it prints, which might be helpful if something goes wrong.
#!/bin/sh
#
# Michael Goffioul
# Updated by P T Withington for Mac OS X
LOGFILE=/tmp/pdf.log
GSBIN=`which pstopdf`
FILENAME=
echo "Executable: $GSBIN" > $LOGFILE
echo "Arguments: |$1|$2|$3|$4|$5|$6|" >> $LOGFILE
# case of no argument, prints available URIs
if [ $# -eq 0 ]; then
if [ ! -x "$GSBIN" ]; then
exit 0
fi
echo "direct pdf \"Unknown\" \"PDF Writing\""
exit 0
fi
# case of wrong number of arguments
if [ $# -ne 5 -a $# -ne 6 ]; then
echo "Usage: pdf job-id user title copies options [file]"
exit 1
fi
# get PDF directory from device URI, and check write status
PDFDIR=${DEVICE_URI#pdf:}
if [ ! -d "$PDFDIR" -o ! -w "$PDFDIR" ]; then
echo "ERROR: directory $PDFDIR not writable"
exit 1
fi
echo "PDF directory: $PDFDIR" >> $LOGFILE
# generate output filename
OUTPUTFILENAME=
if [ "$3" = "" ]; then
OUTPUTFILENAME="$PDFDIR/unknown.pdf"
else
OUTPUTFILENAME="$PDFDIR/${3//[^[:alnum:]]/_}.pdf"
fi
echo "Output file name: $OUTPUTFILENAME" >> $LOGFILE
# run ghostscript
if [ $# -eq 6 ]; then
$GSBIN $6 -o $OUTPUTFILENAME >> $LOGFILE
else
$GSBIN -i -o $OUTPUTFILENAME >> $LOGFILE
fi
# modify ownership and permissions on the file
# - world readable
# - owns to user specified in argument
chmod a+r $OUTPUTFILENAME
if [ "$2" != "" ]; then
chown $2 $OUTPUTFILENAME
fi
exit 0

