Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# code to get maximum dpi of installed or selected printer

Tags:

c#

printing

dpi

I want to get Maximum Dpi of installed or selected printer. I tried

PrinterSettings ps = new PrinterSettings();
        MessageBox.Show(ps.PrinterResolutions.ToString());

and I get this output: System.Drawing.Printing.PrinterSettings+PreinterResolutionCollection (The desired output is 600x600).


1 Answers

Using LINQ:

PrinterSettings ps = new PrinterSettings();
var maxResolution = ps.PrinterResolutions.OfType<PrinterResolution>()
                                         .OrderByDescending(r => r.X)
                                         .ThenByDescending(r => r.Y)
                                         .First();
MessageBox.Show(String.Format("{0}x{1}", maxResolution.X, maxResolution.Y));
like image 111
tukaef Avatar answered Dec 31 '25 16:12

tukaef