4

さまざまなプリンターのトレイの正確な詳細を取得しようとしていますが、問題が発生しました。少し調査した後、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」も存在しません。

だから私の質問はこれです。このリストをフィルタリングして、正しいトレイのみが表示されるようにするにはどうすればよいですか?

4

2 に答える 2

3

foreach を変更し、次のような if ステートメントを追加して、部分的な答えを見つけました...

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

これにより、次の出力が生成されます...

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

理想的ではありませんが、問題の一部は解決します。ただし、存在しない有効なトレイの問題は解決しません。

于 2013-05-01T16:39:52.443 に答える