さまざまなプリンターのトレイの正確な詳細を取得しようとしていますが、問題が発生しました。少し調査した後、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」も存在しません。
だから私の質問はこれです。このリストをフィルタリングして、正しいトレイのみが表示されるようにするにはどうすればよいですか?