简体   繁体   English

为什么PrinterState总是返回null?

[英]Why PrinterState always returns null?

I'm not to be able to get the PrinterState of my Printers. 我无法获取打印机的PrinterState。 I have tested the following code on Linux and on Windows (7) with different Printers (Samsung, Brother (only on Linux), Zebra, ...). 我已经在Linux和Windows(7)上使用不同的打印机(三星,Brother(仅在Linux上),Zebra等)测试了以下代码。 But in every case the PrinterState and the PrinterStateReasons objects are null. 但是在每种情况下,PrinterState和PrinterStateReasons对象都是null。

private void dumpPrinterState() {
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); //get printers

for (PrintService printService : printServices) {
  log.info("---- printer: " + printService);
  log.info("---- state: " + printService.getAttribute(PrinterState.class));
  log.info("---- reason: " + printService.getAttribute(PrinterStateReasons.class));
  }
}

Here is the output with my try on Windows: 这是我在Windows上尝试的输出:

---- printer: Win32 Printer : ZDesigner KR403
---- state: null
---- reason: null
---- printer: Win32 Printer : Samsung CLP-300 Series
---- state: null
---- reason: null
---- printer: Win32 Printer : Microsoft XPS Document Writer
---- state: null
---- reason: null
---- printer: Win32 Printer : Fax
---- state: null
---- reason: null

Anybody knows whats wrong? 有人知道怎么了吗?

You may need to use the toArray() function. 您可能需要使用toArray()函数。 An example of how to use this can be found here on SO: SO printer info 在SO上可以找到如何使用它的示例: SO打印机信息

Please let me know if this helped you. 请告诉我这是否对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM