2

ここでは、デバイスのリストを取得するようにコーディングし、各デバイスのステータスを確認します

DocFlavor myFormat = DocFlavor.SERVICE_FORMATTED.PRINTABLE;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
PrintService[] services =PrintServiceLookup.lookupPrintServices(myFormat, aset);
System.out.println("The following printers are available");
for (int i=0;i<services.length;i++) {
    PrintService printService = services[i];
    PrintServiceAttributeSet printServiceAttributes = printService.getAttributes();
    PrinterState printerState = 
                      (PrinterState)printServiceAttributes.get(PrinterState.class);
    if (printerState != null){
            System.out.println(services[i].getName() + " is online");
    } else {
            System.out.println(services[i].getName() + " is offline");
    }
}

しかし、問題は、プリンターのスイッチがオンまたはオフになっていても、ステータスが「オフライン」になるたびに発生することです

4

1 に答える 1

1

最近、PrintService から別の属性を取得する際に同じ問題が発生しました。

実際、このメソッドは Java クラスに実装されたことがないため、常に null を返します。多くの属性がこれに該当します。

これらの情報を本当に取得したい場合は、Windows の印刷スプーラー DLL を使用するか、プリンターがネット プリンターの場合は SNMP 経由でこれらの情報を照会する必要があります。

于 2013-04-19T13:06:16.760 に答える