Q: When printing PDF documents with Java using jPDFPrint, how can we get more information on the status of printer for instead to know if the printer is turned on or off, if the printer has paper, is out of toner, etc…

A: When printing a PDF document using Qoppa’s jPDFPrint API, all the print methods will return a PrinterException. This is the exception that is returned by Java when trying to print to a given printer. This exception will contain a general message “Printer is not accepting jobs” but no specific reason to indicate what is the exact issue with the printer.

So it will be up to your application to check for the printer status before sending a PDF for printing and by catching this error and doing more investigation on the printer.

Here is a sample code to try to investigate what is a printer status, using the print service attributes (here given here for the default printer). Note that this attribute is NOT going to be supported by all printers.

PrintService printService = PrintServiceLookup.lookupDefaultPrintService();
AttributeSet attributes = printService.getAttributes();
String printerState = attributes.get(PrinterState.class).toString();
String printerStateReason = attributes.get(PrinterStateReason.class).toString();
 
// Status might be IDLE, PROCESSING, STOPPED or UNKNOWN
System.out.println("printerState = " + printerState); 
 
// If your printer state returns STOPPED
System.out.println("printerStateReason = " + printerStateReason); 
if (printerState.equals(PrinterState.STOPPED.toString()) 
{
// identify the print state reason
// COVER_OPEN, INPUT_TRAY_MISSING, TONER_LOW, TONER_EMPTY 
 if (printerStateReason.equals(PrinterStateReason.TONER_LOW.toString()) 
 {
  System.out.println("Toner level is low.");
 }
}