Why does PrinterState always return null?

I can not get the PrinterState of my printers. I tested the following code on Linux and Windows (7) with different printers (Samsung, Brother (Linux only), Zebra, ...). But in each case, the PrinterState and 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)); } } 

Here is the result with my attempt 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 

Does anyone know what is wrong?

0
source share
1 answer

You may need to use the toArray () function. An example of how to use it can be found here: SO: SO Printer Information

Please let me know if this helps you.

0
source

All Articles