views:

476

answers:

3

What is the best way to persist/save printer settings in .Net? There used to be a bug in .Net 1.1 in the serialization of the PrinterSetting object and there were some workarounds but I'm wondering if there isn't a better or easier way of doing this in the more recent versions of the framework.

The main use case is to allow a user to define, using the standard printer setting user interfaces, all print details (including printer-specific options) for a given printer and have these saved so they get restored the next time the user prints to that printer.

+1  A: 

You should use the class PrinterSettings.

Dmitry Shechtman
A: 

not programmatic answer would be: use print management console from 2003 r2 server adminpack to Export Printer configuration. Maybe that feature has an API for it, wich can be called from .net.

+1  A: 

I did a pretty ghetto method of dumping the current DEVMODE and overwriting it back when they want to use it again to send some proprietary printer settings to a copier machine at work. I couldn't find a better way to get to some of the properties that simply weren't exposed via the printing API (such as proprietary stapling and folding options on an old Fiery controller...I think the new XPS printer model has support for these, but lord only knows when we'll start seeing industry support for that).

The main caveat is that it would not be portable across machines or across different versions of the same printer driver. For me, that's no big deal since it's a controlled office environment. For you, I guess it would depend on the context of how your users use the program.

Good luck!

Nicholas Piasecki
Excellent article. Thanks a lot for the complete write-up!
Renaud Bompuis
With the advent of XPSDrv printers and PrintTickets, a better, more portable solution is to get a print ticket and use it. A print ticket is a XML-serialized form of the devmode structure. Refer this[this][1] [1]: http://msdn.microsoft.com/en-us/library/system.printing.printticket(VS.85).aspx
dirkgently
@dirkgently Thanks for the tip. We were on 2.0 at the time. Indeed, the method that I elaborate on is most useful in situations where you have an old GDI printer that doesn't expose things via GetDeviceCaps and has no documentation/capability for ExtEscape().
Nicholas Piasecki