Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the best way to get the default printer in .NET

Tags:

.net

I need to get the default printer name. I'll be using C# but I suspect this is more of a framework question and isn't language specific.

like image 704
Kevin Gale Avatar asked Sep 17 '08 18:09

Kevin Gale


People also ask

How do I change the default printer in C#?

InteropServices; Step 3: Use the following function to set desired printer as default printer. PrinterClass. SetDefaultPrinter("Paste your desired Printer Name here");


1 Answers

The easiest way I found is to create a new PrinterSettings object. It starts with all default values, so you can check its Name property to get the name of the default printer.

PrinterSettings is in System.Drawing.dll in the namespace System.Drawing.Printing.

PrinterSettings settings = new PrinterSettings(); Console.WriteLine(settings.PrinterName);

Alternatively, you could maybe use the static PrinterSettings.InstalledPrinters method to get a list of all printer names, then set the PrinterName property and check the IsDefaultPrinter. I haven't tried this, but the documentation seems to suggest it won't work. Apparently IsDefaultPrinter is only true when PrinterName is not explicitly set.

like image 164
OwenP Avatar answered Sep 19 '22 10:09

OwenP