为什么 PrinterState 总是返回 null? [英] Why PrinterState always returns null?

查看:152
本文介绍了为什么 PrinterState 总是返回 null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法获得打印机的 PrinterState.我已经在 Linux 和 Windows (7) 上使用不同的打印机(三星、Brother(仅在 Linux 上)、Zebra 等)上测试了以下代码.但在每种情况下,PrinterState 和 PrinterStateReasons 对象都是空的.

I'm not to be able to get the PrinterState of my Printers. I have tested the following code on Linux and on Windows (7) with different Printers (Samsung, Brother (only on Linux), Zebra, ...). But in every case the PrinterState and the PrinterStateReasons objects are 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));
  }
}

这是我在 Windows 上尝试的输出:

Here is the output with my try on 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

有人知道怎么回事吗?

推荐答案

您可能需要使用 toArray() 函数.可以在 SO 上找到如何使用它的示例:SO 打印机信息

You may need to use the toArray() function. An example of how to use this can be found here on SO: SO printer info

如果这对您有帮助,请告诉我.

Please let me know if this helped you.

这篇关于为什么 PrinterState 总是返回 null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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