Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the '10.4: Create a virtual PDF printer' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Create a virtual PDF printer
Authored by: Michael Longval on Sep 06, '05 11:44:33PM
How to setup a virtual printer on MacOSX 10.4 (Tiger).

I decided to condense the Virtual Printer HOW-TO on, since it spans many postings and deals with both 10.3 and 10.4, and therefor was a little too confusing at first.

NB: I have installed and tested this on a updated 10.4.2 system (Powerbook), and it works as advertised.

(Please excuse my liberal use of cut and paste from the previous postings.)

Why create a virtual printer?I know that you can always select "Save as PDF" when printing, but I had a situation where I wanted to be able to print to PDF without having to go through the Print dialog. Also sometimes the application disables "Save as PDF".

Here's what you need to do (in a Terminal):

- Copy the included script to:

- Make it executable by everyone: 

     % sudo chmod a+x /usr/libexec/cups/backend/pdf

- You must restart the CUPS daemon, so it finds your new backend and model :  
    % sudo killall -HUP cupsd

- Now you can configure your virtual printer using the Printer Setup Utility. 

- In the Printer Setup Utility click the 'Add' button.  
- In the 'Printer Browser' window that opens you hold down the key while clicking 'More Printers...'.

- Then, finally, you will see the 'Advanced' option in the drop-down menu at the top.

- After you've selected 'Advanced' you can select 'PDF Writing' from the 'Device:' drop-down menu. (This comes from the "pdf" script that you added to /usr/libexec/cups/backend/)

- For "Device Name:", give it something descriptive: like PDFWriter or VPrinter.

- For the device URI, use "pdf://tmp" , it is a good choice as it gets cleaned out automatically when you restart.If you want to put the files somewhere else, specify it.

- For the printer model leave it as Generic.(I deleted the reference to using the Adobe distiller driver that was present in the original posting.)

- 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.

The script checks to see if the output file exists, it creates a new name. ( This was important because printing multiple worksheets out of excel causes each worksheet to be seen as a unique print job, and each subsequent sheet overwrote the previous one.)

Remember your files will be printed to /tmp and will therefor be lost if you don't copy them to somewhere safe before you restart the system.(/tmp get cleaned out at system restart.)

In OSX 10.4 (Tiger):Create a SmartFolder on the Desktop, that searches /tmp for PDFs and call it "PDFWriter_spool".

Your printed files will always be easy to reach this way.

Here is the latest version of the script:(version as of July 16 2004 by n9yty)

# Michael Goffioul
# Updated by P T Withington for Mac OS X
# Updated by Richard Bronosky
# Updated by Steve Palm (N9YTY) - case insensitive URI, unique output files


echo "Script:           $0" > $LOGFILE
echo "Executable:       $GSBIN" >> $LOGFILE
echo "job:              $1" >> $LOGFILE
echo "user:             $2" >> $LOGFILE
echo "title:            $3" >> $LOGFILE
echo "num-copies:       $4" >> $LOGFILE
echo "options:          $5" >> $LOGFILE
echo "filename:         $6" >> $LOGFILE

# case of no argument, prints available URIs
if [ $# -eq 0 ]; then
  if [ ! -x "$GSBIN" ]; then
    exit 0
  echo "direct PDF \"Unknown\" \"PDF Writing\""
  exit 0

# 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

# get PDF directory from device URI, and check write status
URI_PRE=`echo $DEVICE_URI | cut -c 1-3 | tr "[a-z]" "[A-Z]"`
URI_BODY=`echo $DEVICE_URI | cut -c 4-`
echo "Device URI: $DEVICE_URI" >> $LOGFILE

if [ `echo $PDFDIR|cut -c1-3` = //~ ]; then
  PDFDIR=/Users/$2`echo $PDFDIR|cut -c4-`
  # This step added by Richard Bronosky to allow referencing the users home directory
if [ ! -d "$PDFDIR" -o ! -w "$PDFDIR" ]; then
  echo "ERROR: directory $PDFDIR not writable"
  exit 1

echo "PDF directory:    $PDFDIR" >> $LOGFILE

# generate output filename
if [ "$3" = "" ]; then

typeset -i I=1
while [ -e $OUTPUTFILENAME ]

echo "Output file name: $OUTPUTFILENAME" >> $LOGFILE

# run ghostscript
if [ $# -eq 6 ]; then

# modify ownership and permissions on the file
#  - world readable
#  - owns to user specified in argument
if [ "$2" != "" ]; then

exit 0

[ Reply to This | # ]
10.4: Create a virtual PDF printer
Authored by: johnpateman on Oct 29, '05 07:00:40AM

This is a great hint and works really well. I have one problem though - the owner of the file stubbornly remains as root. I have checked through the tail end of the code and inspected the logfile but no avail. The log file shows $2 as my corrrect username. The chmod step works fine, $2 is obviously !="" so can't understand while file remains root:staff. This is really relativly minor but a real annoyance! I see this problem has been reported previously.
Any advice?

[ Reply to This | # ]
10.4: Create a virtual PDF printer
Authored by: Dezro on Mar 14, '06 08:44:49AM

This is a little late, but change the chown line to:
/usr/sbin/chown $2 $OUTPUTFILENAME

Apparently /usr/sbin isn't in the printer thing's $PATH.

[ Reply to This | # ]
10.4: Create a virtual PDF printer
Authored by: después on Mar 27, '07 01:00:28PM
I changed
/usr/sbin/chown $2 $OUTPUTFILENAME
and it worked. (Better than giving rights to everyone.)

[ Reply to This | # ]
10.4: Create a virtual PDF printer
Authored by: zacht on Apr 04, '06 10:04:20PM

Not working in 10.4.5.

[ Reply to This | # ]
10.4: Create a virtual PDF printer WORKS
Authored by: mizraith on Jun 15, '06 06:20:49PM
Works like a charm on latest 10.4.x as of June, 06.

MINOR PROBLEM: Even though, I made sure to edit the chown line of the above posting to add the path (/usr/sbin/chown $2 $OUTPUTFILENAME) the doc is still owned by root. Anybody good at scripts who can tell me how to change that chown line or chmod line?
WORKAROUND: Open the PDF, save it to another folder somewhere. Create a chron job to clean the originals nightly.

+ Also, got it to work from my Windoze XP box. Here's what I did:

- After following the above instructions to the letter (well, almost, I did set the print path to inside a SAMBA shared directory), I opened up the Control Panel and verified that the PDFWriter was shared (under Printers & Faxes).

- I also went to the CUPS control panel (browse to to verify that the PDFWriter was there.

- On WinXP, I clicked on Printers and went through the Add Printer 'wizard', selected Network Printer.

- Entered my server's IP address:

- Selected print driver by GENERIC and used the "MS Publisher Color Printer" driver.

Works like a freakin charm! Thanks to all those above who have been hammering this one out.

[ Reply to This | # ]
10.4: Virtual PDF Printer (ownership)
Authored by: mizraith on Jun 15, '06 06:38:54PM

Duh, To answer my own above "PROBLEM"

Simple enough to make ownership for all, change the chmod line (by adding "+w") to:


Lets users grab their file and clear out the queue on their own.

[ Reply to This | # ]