-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
This issue was reported by a premier customer as AzDo bug 1090547 on Windows.
The customer wants to determine if a printer supports color printing and uses PrinterSettings.SupportsColor property. However this property returns invalid values for some printers ("MS Publisher Color Printer" for example). It seems that we are using incorrect API, as GetDeviceCaps(BITSPIXEL) returns "Number of adjacent color bits for each pixel."
runtime/src/libraries/System.Drawing.Common/src/System/Drawing/Printing/PrinterSettings.Windows.cs
Lines 516 to 522 in 1cf033d
| public bool SupportsColor | |
| { | |
| get | |
| { | |
| return GetDeviceCaps(Interop.Gdi32.DeviceCapability.BITSPIXEL, 1) > 1; | |
| } | |
| } |
DeviceCapabilitiesW function is the correct choice to implement SupportsColor:
DC_COLORDEVICE : If the printer supports color printing, the return value is 1; otherwise, the return value is zero.
Workarounds are to P/Invoke DeviceCapabilities, use WPF - PrintQueue.PrintCapabilities.OutputColorCapability and search for OutputColor.Color, or to use PrintDocument.DefaultPageSettings.Color property, if you need the active selection rather than a capability.
<Setup MS Publisher Color Printer>
1. [Win+R] and run “control” to open control panel.
2. Select “View devices and printers”.
3. Click "Add a Printer" menu and then click "The printer that I want isn’t listed " when the wizard launches.
4. Select "Add a local printer or network printer with manual settings" and click "Next".
5. Click "Use an existing port" and select port whichever you like such as “LPT1: (Printer Port)” and click “Next”.
6. Select "MS Publisher Color Printer" from "Generic" and click "Next" to complete the rest of the wizard.
7. Right click "MS Publisher Color Printer" you added and select “Printing Preferences”.
8. In "Paper/Quality" tab, verify that color is supported and close the dialog.
After this printer is installed, run the following code:
static void PrinterSettingsTest()
{
PrintDocument pd = new PrintDocument();
foreach (string name in PrinterSettings.InstalledPrinters)
{
pd.PrinterSettings.PrinterName = name;
Console.WriteLine($"{name} {pd.PrinterSettings.SupportsColor} {pd.DefaultPageSettings.Color}");
}
Console.ReadLine();
}
Expected: PrinterSettings.SupportsColor returns true for "MS Publisher Color Printer"
Actual: it return false for local publisher printer