2
votes

I'm trying to determine the current paper type selection on the default printer using C#.

I've determined the default printer using WMI and enumerating through the Properties collection, I can see there's a CurrentPaperType string property, but on both printers in the office, its set to an empty string.

MSDN's documentation starts rambling on about printers implementing this standard blah blah, but very little in the way of practical advice :-

Type of paper the printer is using. Must be expressed in the form specified by the ISO/IEC 10175 Document Printing Application (DPA), which is summarized in Appendix C of RFC 1759 (Printer MIB). This property is inherited from CIM_Printer.

I can retrieve a list of all paper types the chosen printer supports, but it doesn't tell me which one it is currently set to.

I'm creating a dynamic report in memory and then spitting it out to the printer in one hit, so I need to know the paper size in order to correctly set margins, column widths etc.

Anyone had any success retrieving this information?

2

2 Answers

5
votes

Don't use WMI unless you really need to. Use the built in .Net classes like Foxfire said. You can get a printer using the following:

System.Drawing.Printing.PrinterSettings printer = new System.Drawing.Printing.PrinterSettings();
printer.PrinterName = "YourPrinterName";

You can then access all the properties you require through:

printer.DefaultPageSettings;
2
votes

Is there any particular reason why you use WMI instead of the .Net printer classes in System.Drawing.Printing?

You could easily get your Info through the PaperSources property of the PrinterSettings class which contains all PaperKinds that are currently available in the printer (could be more than one because several printers have multiple trays)