Re: Printing File to PDF from Native Application
Re: Printing File to PDF from Native Application
- Subject: Re: Printing File to PDF from Native Application
- From: Scott Ribe <email@hidden>
- Date: Tue, 09 Dec 2008 09:45:24 -0600
- Thread-topic: Printing File to PDF from Native Application
There is no reliable documented API for switching the default printer. There
are workarounds which might or might not work in the future.
Briefly: there are CUPS techniques for setting the default printer. Under
10.4 these worked. Under 10.5 these work unless the user has chosen "Last
Printer" in System preferences as the default printer, in which case the
CUPS setting is ignored. So you have to check that preference, and
potentially switch it temporarily. Hint:
/usr/bin/defaults -currentHost read com.apple.print.PrintingPrefs
UseLastPrinterAsCurrentPrinter
There is no system facility for creating a printer which creates a PDF file.
There is a download called CUPS-PDF which will do this. There are certain
things about it that I don't like WRT file naming & placement. There are
also some shell scripts floating around that accomplish the same thing. If
you examine them, you find that they're basically just passing data through,
since CUPS sends PDF to the driver. So what they really do is a batch of
setup WRT to parsing command-line arguments, naming &creating & placing a
file, and so on.
The biggest problem with these is that they assume one instance, and if you
try to create multiple printer instances, they all put files in the same
place. So your custom printer would potentially interfere with ones set up
by a user, rather than being truly dedicated to your use. It would be
possible to modify one of these to name & place the PDF files as you prefer.
I would have done that, but I hate bash scripting, so I wrote my own in
Ruby.
In or to print a file using another program, you want to look into
AppleScript and possibly Launch Services.
--
Scott Ribe
email@hidden
http://www.killerbytes.com/
(303) 722-0567 voice
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden