By Tinkster at 2005-10-07 03:48
Note: for this to work CUPS needs to be installed and functional.
CUPS is very powerful, with its backends and filters very interesting things can be done. One of the many possible uses is to create a printer-type PDF, which, when used as a print-target will create a PDF file rather than producing a print-out on a physical device.
For the following activities we need to be user root:
1. Create a sub-directory in CUPS directory sturcture
Put the following script into the newly created directory, e.g
Then highlight the following script with the mouse, and middle-click into the terminal session with vim open.
After the middle-click, press ESC, :wq<RET> to save the file, followed by a
# Convert PostScript to PDF.
case "$1" in
-*) OPTIONS="$OPTIONS $1" ;;
*) break ;;
if [ $# -lt 1 -o $# -gt 2 ]; then
echo "Usage: `basename $0` [options...] input.ps [output.pdf]" 1>&2
if [ $# -eq 1 ]
# Doing an initial 'save' helps keep fonts from being flushed between pages.
exec gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
-sOutputFile=$outfile $OPTIONS -c save pop -f $infile
exec chmod a+r $outfile
to make it executable.
chmod 755 /usr/lib/cups/pdf/ps2pdf.cups
2. Create the backend
The next bit of our PDF printer driver goes into /usr/lib/cups/backend
The back-end directory holds several binary executables that take care of varied printing methods, e.g. parallel, usb, ...
We're now going to add a shell-script that handles pdf-files!
As before, copy & paste time
And as before, this script needs to be made executable, too.
# filename of the PDF File
# no argument, prints available URIs
if [ $# -eq 0 ]; then
if [ ! -x "$PDFBIN" ]; then
echo "direct pdf \"Unknown\" \"PDF Creator\""
# case of wrong number of arguments
if [ $# -ne 5 -a $# -ne 6 ]; then
echo "Usage: pdf job-id user title copies options [file]"
# get PDF directory from device URI, and check write status
if [ ! -d "$PDFDIR" -o ! -w "$PDFDIR" ]; then
echo "ERROR: directory $PDFDIR not writable"
# generate output filename
if [ "$3" = "" ]; then
if [ "$2" != "" ]; then
echo "PDF file: $OUTPUTFILENAME placed in: $PDFDIR" >> $LOGFILE
# run ghostscript
if [ $# -eq 6 ]; then
$PDFBIN $6 $OUTPUTFILENAME >& /dev/null
$PDFBIN - $OUTPUTFILENAME >& /dev/null
chmod 755 /usr/lib/cups/backend/pdf
3. Download and install distiller.ppd
The printer definition file for distiller is freely available from the adobe-website, if you have a windows-installation handy follow steps 1 to 5 of the instructions...
If you don't: there's some other sites on the web that hold just the ppd rather than an installer. Google is your friend.
Once you have downloaded it add it to your CUPS' printer-model
cp distiller.ppd /usr/share/cups/model/distiller.ppd
and then, the second to last step:
4. Create the printer object
To be able to use all the pre-requisits that held us up ....
lpadmin -p PDF -v pdf:/directory/of/your/choice/ -E -P /usr/share/cups/model/distiller.ppd
5. Re-start CUPS
Now that all the set-up and installation is done, we need to let the CUPS daemon know about the new printer, too.
To achieve that we restart the daemon.
And if all went well we should now have a printer-object that will create PDFs for us.