This discussion is archived
0 Replies Latest reply: Feb 27, 2013 10:09 PM by 993856 RSS

Get PrinterStateReasons

993856 Newbie
Currently Being Moderated
Hi,

I want to run a printing job using java and before that I need to check printer State.(I found this thread on same problem but unsolved. Re: How to get a PrinterState ) Which means whether covers are open, Trays out of paper, Paper Jam etc. I see these things are available inside PrinterServiceAttribute PrinterStateReason PrinterStateReason . When I loop through attributes available in PrintService, PrintStateReason is null(Primarily PrinterStateReasons is null. because API documentation says PrinterSateReason is inside PrinterStateReasons). Following is what I try to do

PrintService[] allServices = PrintServiceLookup.lookupPrintServices(null, null);
          
          for (PrintService ps : allServices){
               AttributeSet attSet = ps.getAttributes();
               
               System.out.println("Available printers support attribute -> "+ ps.getName());
               
               PrinterState prnState = (PrinterState)ps.getAttribute(PrinterState.class);
               
               System.out.println("PrinterStats -> "+ prnState);
               
               log.info("Available printers support attribute -> ");

          for(Attribute att:attSet.toArray()){
               String attName = att.getName();
               String attValue = attSet.get(att.getClass()).toString();
               System.out.println(attName + " : " + attValue);
               log.info(attName + " : " + attValue);
          }
     }

If printer is not supporting this attribute how can we check whether a particular printer supports this?

Thank you

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points