Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!


Click here to return to the '10.4: Create a virtual PDF printer' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
10.4: Create a virtual PDF printer
Authored by: hschot on Mon, Jun 27 2005 at 7:34AM PDT
In Tiger you have to open the printer list, then click the 'Add' button. In the 'Printer Browser' window that opens you hold down the <option> 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.

[ Reply to This | Parent | # ]
10.4: Create a virtual PDF printer
Authored by: Michael Longval on Tue, Sep 6 2005 at 11:44PM PDT
How to setup a virtual printer on MacOSX 10.4 (Tiger).

I decided to condense the Virtual Printer HOW-TO on macosxhints.com, 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:
         /usr/libexec/cups/backend/pdf

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


#!/bin/sh
#
# 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

LOGFILE=/tmp/PDF.log
GSBIN=/usr/bin/pstopdf
FILENAME=

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
  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
URI_PRE=`echo $DEVICE_URI | cut -c 1-3 | tr "[a-z]" "[A-Z]"`
URI_BODY=`echo $DEVICE_URI | cut -c 4-`
DEVICE_URI="${URI_PRE}${URI_BODY}"
echo "Device URI: $DEVICE_URI" >> $LOGFILE

PDFDIR=${DEVICE_URI#PDF:}
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
fi
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

FBASE=`basename ${OUTPUTFILENAME} .PDF`
typeset -i I=1
while [ -e $OUTPUTFILENAME ]
do
   OUTPUTFILENAME="${PDFDIR}/${FBASE}_$I.PDF"
   I=$I+1
done

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



[ Reply to This | Parent | # ]