我正在尝试获取各种打印机托盘的正确详细信息,但是遇到了问题。经过一番研究,我添加了 ReachFramework.dll 以及
using System.Drawing.Printing;
要获取打印机托盘的名称,我运行以下代码...
PrintDocument printDocument = new PrintDocument();
printDocument.PrinterSettings.PrinterName = "<Windows Printer Name>";
foreach (PaperSource paperSource in printDocument.PrinterSettings.PaperSources)
{
Console.WriteLine(paperSource.ToString());
}
...替换“Windows 打印机名称”。对于某些打印机,它工作得很好,我得到类似以下输出的东西......
[PaperSource Auto Tray Select Kind=AutomaticFeed]
[PaperSource Tray 1 Kind=Upper]
[PaperSource Tray 2 Kind=Middle]
[PaperSource Tray 3 Kind=Lower]
[PaperSource Bypass Tray Kind=Manual]
这是你所期望的。但是对于某些打印机,我得到以下...
[PaperSource Automatically Select Kind=FormSource]
[PaperSource Printer auto select Kind=Custom]
[PaperSource Manual Feed in Tray 1 Kind=Custom]
[PaperSource Tray 1 Kind=Custom]
[PaperSource Tray 2 Kind=Custom]
[PaperSource Tray 3 Kind=Custom]
[PaperSource Unspecified Kind=Custom]
[PaperSource Plain Kind=Custom]
[PaperSource HP Matte 90g Kind=Custom]
[PaperSource Light 60-74g Kind=Custom]
[PaperSource Bond Kind=Custom]
[PaperSource Recycled Kind=Custom]
[PaperSource HP Matte 105g Kind=Custom]
[PaperSource HP Matte 120g Kind=Custom]
[PaperSource HP Soft Gloss 120g Kind=Custom]
[PaperSource HP Glossy 130g Kind=Custom]
... Additional 20 lines ...
这台打印机返回了 36 个纸盘,但只有前 6 个是有效的纸盘类型。此外,打印机仅配备 2 个标准纸盘,因此“纸盘 3”也不存在。
所以我的问题是这个。如何过滤此列表以便只显示正确的托盘?