Search code examples
c#printingdpi

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


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).


Solution

  • 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));