为什么PrinterState总是为空?

时间:2015-12-21 16:02:56

标签: java printing java-print

我需要对我的打印机有更多的控制权,然后我试图获得打印机的PrinterState,然后使用PrintStareReasons。我的代码如下:

21.12.2015 16:48:56 INFO  PrintWorker:142 - Check --------------
21.12.2015 16:48:58 INFO  PrintWorker:151 - State false
21.12.2015 16:48:58 INFO  PrintWorker:154 - copies-supported
21.12.2015 16:48:58 INFO  PrintWorker:154 - finishings
21.12.2015 16:48:58 INFO  PrintWorker:154 - job-sheets
21.12.2015 16:48:58 INFO  PrintWorker:154 - job-sheets
21.12.2015 16:48:58 INFO  PrintWorker:154 - number-up
21.12.2015 16:48:58 INFO  PrintWorker:154 - number-up
21.12.2015 16:48:58 INFO  PrintWorker:154 - number-up
21.12.2015 16:48:58 INFO  PrintWorker:154 - number-up
21.12.2015 16:48:58 INFO  PrintWorker:154 - number-up
21.12.2015 16:48:58 INFO  PrintWorker:154 - number-up
21.12.2015 16:48:58 INFO  PrintWorker:154 - orientation-requested
21.12.2015 16:48:58 INFO  PrintWorker:154 - orientation-requested
21.12.2015 16:48:58 INFO  PrintWorker:154 - orientation-requested
21.12.2015 16:48:58 INFO  PrintWorker:154 - orientation-requested
21.12.2015 16:48:58 INFO  PrintWorker:154 - page-ranges
21.12.2015 16:48:58 INFO  PrintWorker:154 - media
21.12.2015 16:48:58 INFO  PrintWorker:154 - spool-data-destination

谷歌搜索我也写了getAttributes()来获取所有的属性,但PrinterState不存在。

这是所有属性的列表:

logger.info("State " + printer.isAttributeCategorySupported(PrinterState.class));

虽然

21.12.2015 16:48:58 INFO  PrintWorker:151 - State false

总是回归:

{{1}}

我在Linux和Windows(7)上测试过以下代码,但没有一个返回实际状态。可能是什么问题呢?打印机,驱动程序或我的代码?

1 个答案:

答案 0 :(得分:6)

如果打印请求中的打印服务isAttributeCategorySupported()返回false,

true将返回supports specifying a doc-level or job-level attribute in category

看一下the official oracle documentation会让我的观点更加清晰