我试图获得各种打印机托盘的正确详细信息,但遇到了问题。一些研究之后,我已经添加了ReachFramework.dll也获取额外的PaperSource详细信息
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'也不存在。
所以我的问题是这样的。我如何过滤这个列表,以便只显示正确的托盘?
他们都是有效的打印机吗?你如何迭代打印机? – jle 2013-05-01 17:27:46
在本例中没有必要遍历打印机,因为您只需完全命名它即可,但是我使用System.Printing.LocalPrintServer()。GetPrintQueues(enumFlags)来获取Windows打印机名称。 – Thundter 2013-05-02 09:23:42