How to access the status of the printer?

前端 未结 4 1781
醉酒成梦
醉酒成梦 2020-12-03 20:03

I need to know the Printer Status. I need to control the Printer Status using Java Program. Example

  1. Check the Printer status, weather will it accept the Job
4条回答
  •  被撕碎了的回忆
    2020-12-03 20:35

    I was told one could check the printer status this way:

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

    Sadly it seems that my printer doesn't have support for printerState so I can't test it.

提交回复
热议问题