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));
}
}
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
Anybody knows whats wrong?
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.