Question

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.

Was it helpful?

Solution

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!

OTHER TIPS

You should use the class PrinterSettings.

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.

The issues with the serialization of a PrinterSetting object is about the PrintFileName Property.

This property has to have a value to avoid an exception when you try to unserialize back the object.

If you want to save PrinterSettings of a reportviewer

Me.ReportViewer.PrinterSettings.PrintFileName = "abc"
My.Settings.PrinterSettings = Me.ReportViewer.PrinterSettings
My.Settings.Save()

And getting them back

If My.Settings.PrinterSettings IsNot Nothing Then Me.ReportViewer.PrinterSettings = My.Settings.PrinterSettings

Anyway saving the PrinterSetting will only persist the "standard" value. You have to use DEVMODE if you want to persist the exotic stuff each driver have.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top