让更多PaperSource细节 [英] getting additional PaperSource details

查看:551
本文介绍了让更多PaperSource细节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让各种打印机的托盘正确的细节但是所遇到的一个问题。经过一番研究,我添加了ReachFramework.dll也

I'm trying to get the correct details of trays of various printers however have come across a problem. After a bit of research I've added the ReachFramework.dll and also

using System.Drawing.Printing;

要获得托盘的名字我运行下面的code打印机...

To get the names of the trays for a printer I run the following code...

PrintDocument printDocument = new PrintDocument();
printDocument.PrinterSettings.PrinterName = "<Windows Printer Name>";

foreach (PaperSource paperSource in printDocument.PrinterSettings.PaperSources)
{
    Console.WriteLine(paperSource.ToString());
}

...取代Windows打印机名称。对于某些打印机它的伟大工程,我得到类似如下的输出...

...replacing 'Windows Printer Name'. For some printers it works great and I get something like the following output...

[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]

这是你所期望的。然而,对于某些打印机出现以下...

Which is what you would expect. However for some printers I get the following...

[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'也不存在。

This printer returned 36 trays but only the first 6 are valid tray types. Additionally the printer is only equipped with 2 standard trays, so 'Tray 3' is doesn't exist either.

所以我的问题是这样的。我怎样才能过滤此列表,以便只有正确的托盘都出现了?

So my question is this. How can I filter this list so only the correct trays are showing?

推荐答案

发现改变的foreach并增加了部分答案的,如果像下面的语句...

Found a partial answer by changing the foreach and adding an if statement like the following...

foreach (PaperSource paperSource in printDocument.PrinterSettings.PaperSources)
{
    if (paperSource.RawKind < 1000)
    {
        Console.WriteLine(paperSource.ToString());
    }
}

这将产生以下输出...

This produces the following output...

[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]

虽然不是理想它并解决问题的一部分。但是,它没有解决根本不存在有效的托盘的问题。

While not ideal it does solve the part of the problem. It doesn't however solve the issue of valid trays that do not exist.

这篇关于让更多PaperSource细节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆