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

10.3: Create a virtual PDF printer UNIX
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. I suspected there was a simple way to do this with CUPS (the printing architecture underlying OS X). I found an article by Michael Goffiou that gave a simple shell script that would create a 'backend' for CUPS that does the trick. There are a few differences for Mac OS X, so I've modified his original script to fit. Here's what you need to do (in a Terminal):
  1. Copy the included script (in the main body of the hint) to /usr/libexec/cups/backend/pdf

  2. Make it executable by everyone:
     % sudo chmod a+x /usr/libexec/cups/backend/pdf
  3. (Optional) If you have the Acrobat Distiller PPD, put a copy in /usr/share/cups/model

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

[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
    •    
  • Currently 2.22 / 5
  You rated: 4 / 5 (9 votes cast)
 
[88,775 views]  

10.3: Create a virtual PDF printer | 48 comments | Create New Account
Click here to return to the '10.3: 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.3: Create a virtual PDF printer
Authored by: VEGx on Nov 25, '03 11:52:01AM

If someone knows how to configure it on 10.2.8, let me know.



[ Reply to This | # ]
Trying for 10.2.8
Authored by: Black on Nov 25, '03 12:43:57PM

I am running 10.2.8 and I have almost got it working.

One thing the post doesn't mention is that you need to have ghostscript installed. Mine was installed through Fink, so I changed the

GSBIN=`which ps2pdf`
to
GSBIN=/sw/bin/ps2pdf

Once I did that, I could follow the steps listed above pretty exactly. However, it didn't produce a pdf file...

I called mine topdf (mostly because I am lazy) and I tried to print using

lpr -P topdf zsh.ps
(where zsh.ps is just some postscript file I had lying around). Everything looked kosher in the log, but no pdf files were hanging out in /tmp. Very sad. Anyone have any ideas?

Log contents:


Executable: /sw/bin/ps2pdf
Arguments: |333|candrews|zsh.ps|1|||
PDF directory: //tmp
Output file name: //tmp/zsh_ps.pdf



[ Reply to This | # ]
Trying for 10.2.8
Authored by: ptwithy on Nov 25, '03 03:20:48PM

Panther has ghostscript installed as 'pstopdf', I assume as part of fax printing, which is why I renamed it from the original script. I would think that a fink installation of ghostscript should work, so I can't explain why you are having trouble. Don't have access to Jaguar to test...



[ Reply to This | # ]
Trying for 10.2.8
Authored by: kerbaugh on Nov 30, '03 12:22:45AM

ps2pdf works a little better for me than pstopdf but the executable's syntax is different, without as many options. You don't use a -o switch, you simply list the output file as the second non-option argument. You also don't use the -i switch, you use a dash, "-" by itself. Thus I use the following lines in my script:

$GSBIN $6 $OUTPUTFILENAME >> $LOGFILE

$GSBIN - $OUTPUTFILENAME >> $LOGFILE

Try those lines in place of their counterparts in the next to last "if" clause and see if it works then. I made other changes but I think these should be enough.



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: gsdali on Nov 25, '03 12:56:58PM

Fantastic hint, very, very useful.

---
--
Ed Lynch-Bell
dali@zerointegrity.co.uk



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: ssevenup on Nov 25, '03 03:26:42PM
This hint is basically the same idea, or at least another take on a CUPS backend. But, Tom has put many days into refining this. It looks like Panther and Jaguar are similar enough that only minor changes are required.

---
Mark Moorcroft
ELORET Corp. - NASA/Ames RC
Sys. Admin.

[ Reply to This | # ]

10.3: Create a virtual PDF printer
Authored by: oink on Nov 25, '03 05:42:58PM

I never installed ghostscript, but "which pstopdf" returns "/usr/bin/pstopdf". The script works. May be there is a difference between "ps2pdf" and "pstopdf".

If only someone can point me a way to make a ps file short of using the "save to file" output options at the print dialog. Output options seems to be crippled (limited) for super user, which is my normal login. "Save to file" is not available... I have to log in as normal user to do just that!



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: argho on Mar 14, '04 09:23:01AM

One difference between the ps2pdf of AFPL Ghostscript and the pstopdf provided by Apple seems to be the filesize they create with default settings. For a 20 page magazine ps2pdf produces roughly 1MB while pstopdf produces 21MB. Does anyone know how to modify the quality settings of the one provided by Apple?



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: aequitas on Nov 25, '03 05:46:49PM
When i add the printer, make it a desktop icon and use it with a omnioutliner document my /tmp/pdf.log lookes like this:

Executable: /usr/bin/pstopdf
Arguments: |31|johan|motor inkoop|1|AP_D_InputSlot= nocollate media=A4 com.apple.print.PrinterInfo.PMColorDeviceID..n.=164912936 OutputOrder=Normal com.apple.print.JobInfo.PMApplicationName=OmniOutliner com.apple.print.PrintSettings.PMColorSyncProfileID..n.=-1057516797 com.apple.print.PrintSettings.PMCopies..n.=1 com.apple.print.JobInfo.PMJobName='motor inkoop' com.apple.print.PrintSettings.PMColorSpaceModel..n.=0 com.apple.print.JobInfo.PMJobOwner=Johan com.apple.print.PrintSettings.PMFirstPage..n.=1 com.apple.print.PrintSettings.PMCopyCollate..b. com.apple.print.DocumentTicket.PMSpoolFormat=application/pdf com.apple.print.PrintSettings.PMPageRange..a.0..n.=1 com.apple.print.PrintSettings.PMPageRange..a.1..n.=2147483647 com.apple.print.PrintSettings.PMTotalSidesImaged..n.=1 DestinationPrinterID=PDF_Printer com.apple.print.PrintSettings.PMLastPage..n.=2147483647 com.apple.print.PrintSettings.PMTotalBeginPages..n.=1||
PDF directory: //Users/johan/Desktop
Output file name: //Users/johan/Desktop/motor_inkoop.pdf
%%[ Error: ioerror; OffendingCommand: put ]%%
%%[ Flushing: rest of job (to end-of-file) will be ignored ]%%
%%[ Warning: PostScript error. No PDF file produced. ] %%


Other document's don't work iether.

Any idea what is wrong?

[ Reply to This | # ]
log error
Authored by: cawaker on Nov 25, '03 07:08:17PM

I am runnign into this also trying an efax (.efx) file. I think os x somehow converts it to a postscript file before converting to pdf via the print dialogue. And that step is being skipped with this script, non standard file formats or formats pstopdf doesnt understand wont work.



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: Craigriver on Nov 25, '03 06:17:30PM

What a wonderful community of users! I was thinking about this the other day. About how nice it would be to have a desktop pdfprinter.

Now, can someone put this in plain english so a simple minded person can implement this solution?

Thank you. I can fathom how to get to /cups/ or whatever the hierarchy is here.

Thank you.



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: oink on Nov 25, '03 06:27:01PM

I think you can just make an alias to the whatever_print.app in ~/Library/Printers/ on the Desktop and you have a Desktop printer



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: cawaker on Nov 25, '03 06:48:32PM

so who can come up with a simple way to turn this into a folder action script? drop a file into a folder, bang, out comes pdf, no printing needed. batch pdf converting, haha not a bad idea. I assume since its just a bash script, i can use applescript to just call the terminal commands and such? Actually upon a bit closer looking i think i can modify the postscript to pdf folder action that comes with panther, to work with this script.



[ Reply to This | # ]
PDF Folder actions
Authored by: orpy on Mar 14, '04 05:33:25PM

No need to write one from scratch - Panther is supplied with a folder action script that does this:

Library/Scripts/Folder Action Scripts/convert - PostScript to PDF.scpt



---
--
Martin



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: oink on Nov 25, '03 07:57:37PM

While following this tip, I noticed a separated "Adobe PDF" item in "device" menu (the same menu as PDF Writing). Is this installed by one of my Adobe apps or a stock OS X item? It didn't work wace=I tried to set up a printer with it.



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: SFJeep on Nov 30, '03 12:34:21AM

When I do this there is no "PDF Writer" option for device. Is there something I need to have installed perhaps?



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: Anonymous on Nov 25, '03 10:01:01PM

This would be a perfect hint, but I'm running into two problems.

First, this belongs to 'root' when it prints out; problematic if you want to handle the file.

Also, it comes out as 'untitled.pdf'.

Can I somehow affect either of these, I assume by modifying the 'pdf' script?



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: xandros on Mar 21, '05 04:19:53AM

well so it is change the script to pass different permissions .. though

the
# modify ownership and permissions on the file
comment clearly states where its done :)



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: sboger on Nov 25, '03 10:05:30PM

we've been doing this in the linux world for years...

and we've made it one step better.... you can do it on Panther too..

share that printer using samba for the windows flunkies. now make the folder it drops the pdfs into a windows share...

bang, you have a centrally located office pdf printer..



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: jimcobber on Nov 26, '03 02:31:54PM

How do you setup a windoze 2000 machine to use the printserver after setting up the queue? I drag the one off the share but it just gives you a status of "error". Macs print to the queue no problem.



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: aaronbratcher on Oct 21, '04 05:44:05PM

If anyone has a solution to this, I would appreciate it too. Shared the PDF driver to windows clients, installed it on XP and told XP it was a postscript printer. (Apple 16/600 I think) All it does is pause the printer.



[ Reply to This | # ]
How to put on users' desktop?
Authored by: sjonke on Nov 26, '03 11:19:17AM

Is it possible to enter a path such as ~/Desktop so that it will make the file on the users desktop? I tried this but the printer doesn't seem to work. I don't want to enter a full path because that would only work for the user with that particular desktop. Is it possible?

---
--- What?



[ Reply to This | # ]
How to put on users' desktop?
Authored by: oink on Nov 26, '03 02:03:51PM

/Users/yourlogin/desktop, eventhough my /Users is only a symolic link to some other partition. It works for me



[ Reply to This | # ]
How to put on users' desktop?
Authored by: SeanAhern on Dec 03, '03 11:08:47PM

Um...he wanted a way for it to work for all users of the system, not just one particular user.

---
-Sean



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: ths on Nov 26, '03 11:51:07AM

This is a really great hint! Unfortunately, in my case, the PDF files will always be US letter size instead of the papersize I set in the document, like A5 or A4. It seems that US letter size is hardcoded into pstopdf. I've been toying around with settings and man pages, but wasn't very succesful. So, does anybody know how to get around this 'feature'? Thanks in advance :-)



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: ths on May 31, '04 02:40:01PM

Oh, well, I'm answering my own question: when I changed the printer driver from "Generic" to something different e.g. "Apple Color LaserWriter 12/600 PS v2014.108" I was at least able to print to A4 instead of US letter format. Any other paper formats are not supported, apparently. But better than nothing, eh?



[ Reply to This | # ]
Got it working with ~/Desktop
Authored by: BrunoUsesBBEdit on Dec 11, '03 01:20:59PM
Great work!!!

But, I had a big problem with "PDF Printing" not showing up in my list. The problem was that all of the double quotes were backslashed in the code sample in the main hint body.

I also went ahead and solved the problem of allowing the printer to be specified with a Device URI of PDF://~/Desktop to get it to print on the users desktop or PDF://~/Documents... etc.

And I made the log more concise while I was at it.


#!/bin/sh
#
# Michael Goffioul
# Updated by P T Withington for Mac OS X
# Updated by Richard Bronosky

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

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

---

--==< B r u n o >>==--

[ Reply to This | # ]

Got it working with ~/Desktop
Authored by: whiteinge on Jan 15, '04 04:46:51PM

Thanks Bruno, that really hooked me up!



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: error1901 on Jan 16, '04 06:22:43AM

We wanna do the same thing on Mac OS X Panther Server. But there is no way to choose the "pdf-writing" option because the option key doesn`t work, so you don`t get an extended list to choose "pdf-writing". Anyone got an idea who to integrade the script?

ErRor1901



[ Reply to This | # ]
10.3: Create a virtual PDF printer
Authored by: xandros on Mar 21, '05 04:29:40AM

to setup a printer when the command click doesnt work ..

use the cups web interface under http://localhost:631/

well choose p. ex as --
Name:pdfWriter
Device:Pdf Writing
URI: pdf://tmp/
** as output model an arbitrary one **

!** and as final step setup the "model" of the freshly created printer in the print center to "generic" or an apple postscript writer in the info dialog (command i) .. else only error msg will show up in the pdf.log file



[ Reply to This | # ]
Still seeing Print dialog
Authored by: sudama on Apr 19, '04 12:19:06PM

I had a situation where I wanted to be able to print to PDF without having to go through the Print dialog.

This is fantastic and useful, but when printing MS Word documents, I still have to approve the Print dialog. Am I missing something?



[ Reply to This | # ]
Still seeing Print dialog
Authored by: yoc on Jul 02, '04 12:10:10PM
What I've done to bypass the print dialog is an AppleScript saved as an Application. Just write this code :

on open (theItems)
	repeat with aFile in theItems
		tell application "Finder"
			set fileRef to (a reference to file aFile)
			tell application "Microsoft Word"
				open fileRef
				do Visual Basic "ActiveDocument.PrintOut"
				close last document
			end tell
		end tell
	end repeat
end open

Save it as an application, and all you have to do is to drag and drop a Word document on the resulting application to make a PDF without prompt.

---
www.macbidouille.com

[ Reply to This | # ]

10.3: Create a virtual PDF printer
Authored by: n9yty on Jul 16, '04 11:38:07AM
I'll throw out my modifications. First, I changed it so the device-uri in the dialog when you add the printer dosn't have to be case sensitive. This caused me an initial failure until I realized the script was only looking for PDF:// not pdf:// which was the default value. Second, I changed it so that 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. I hope someone finds this useful.

#!/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 | # ]
10.3: Create a virtual PDF printer
Authored by: xandros on Mar 21, '05 04:44:19AM

well i ran across an application that only allowed direct printing without the print dialog .. :/

added to that came that the files that were printed were named the same with a singlepage printout .. so i added a little snippet to the code that prevents the overwrite of an existing pdf file in the output directory .. the distinction gets made by adding multiple x to the end of the filename

the snippet has to be placed before
echo "Output file name: $OUTPUTFILENAME" >> $LOGFILE

[code]
counter=""
while [ -e ${OUTPUTFILENAME//.pdf/}$counter".pdf" ]; do
counter=$counter"x"
done

OUTPUTFILENAME=${OUTPUTFILENAME//.pdf/}$counter".pdf"
[/code]

ohh btw .. the previous poster n9yty made nearly the same modification to his refined script ..



[ Reply to This | # ]
alternative printer setup
Authored by: xandros on Mar 22, '05 07:50:03AM

for those that cant use the print-center .. or want to play around with the web interface of cups http://localhost:631 .. or to have an alternative installation way

as on macos x the pre-installed ppds that come in the web interface (good ones are placed in other directorys accessible only by print-center) arent suitable for the pstopdf conversion you have to copy them over ..

as an example i take the LaserJet 8150 ppd as it worked for me with the pdf backend and produced nice pdf output (centered) unlike the generic one i used before (capped the top of the page as i used the format A4 .. i guess it was for written for Letter output)

decompress the "/Library/Printers/PPDs/Contents/Resources/en.lproj/HP LaserJet 8150 Series.gz" rename the ppd to "HP8150_H.PPD" and place it in "/usr/share/cups/model/" -- now hup the cups daemon again with "sudo killall -HUP cupsd" go to the web interface and you are able to chose this printer .. (ppds from apple are placed in "/System/Library/Printers/PPDs/Contents/Resources/...")

certainly this can also be archived by using the print-center.app .. associated printer model descriptions (ppds) can also be switched there via Information or command-I ..



[ Reply to This | # ]
10.4: Create a virtual PDF printer
Authored by: hschot on Jun 12, '05 04:52:33PM

Just tried the original hint on 10.4 Tiger: Works!



[ Reply to This | # ]
10.4: Create a virtual PDF printer
Authored by: hschot on Jun 27, '05 07:34:08AM

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 | # ]
10.4: Create a virtual PDF printer
Authored by: zacht on Apr 04, '06 09:14:51PM

"PDF Writing" isn't a choice. 10.4.5. Dang. :-(



[ Reply to This | # ]
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 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 | # ]
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
chown $2 $OUTPUTFILENAME
to
/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 127.0.0.1:631) 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:
http://ipaddress:631/printers/PDFWriter

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

chmod a+r+w $OUTPUTFILENAME

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



[ Reply to This | # ]
similar solution for 10.4 Tiger
Authored by: xcgr on May 10, '06 05:02:55PM
If you have Tiger and you want to print files to PDF, another solution is codepoetry's Mac package of the CUPS-PDF module. It seems to work quite well on my computer.

[ Reply to This | # ]
10.3: Create a virtual PDF LOCAL PRINTING
Authored by: mizraith on Jun 30, '06 10:38:29AM

Okay....so the above works. A few more hints for you folks out there.
#1) The easiest way for Windoze lackeys to see the printer (browse for it) is to install Bonjour for Windoze. Then they can use the Bonjour interface to browse for your PDFWriter.
#2) Windows lackeys should use Generic -> MS Publisher Color Printer driver
#3) I set the path for the printer to be inside my local Samba share so that users could get to it.


#4) I had a problem with printing to PDF locally (on the server itself). It would just fail to print the job. This may be because I had gone into the CUPS web interface (127.0.0.1:631) and mucked with my PDFWriter to make it RAW format. The CUPS web interface does NOT have a "Generic" interface.
SOLUTION: Follow the steps to create yet another PDFWriter (call it PDFlocal) and select the Generic interface (just as before), but do NOT muck with it in the CUPS interface. This worked on 10.4.7 and now I can PDF print like a normal OS X box.



[ Reply to This | # ]
10.3: Create a virtual PDF LOCAL PRINTING
Authored by: rgm on Jul 05, '06 04:50:06PM

I get a failure on this. /var/log/cups/error_log says that the backend process "crashed on signal 10!" or "stopped with status 2!"... does anyone know what these mean? Some googling has indicated that signal 10 is a bus error, no idea what status 2 is...



[ Reply to This | # ]