4

Is there are any way to find a printer status using java socket program? This program need to identified printer status. such as

  1. Printer ON/OFF/IDEAL.
  2. Current Job.
  3. Paper level in try.
  4. toner leave.

I used javax.print API, this help me to print a documents in the printer and it list down 4 attributes

  • printer-is-accepting-jobs: accepting-jobs

  • printer-name: myPrinter

  • queued-job-count: 0

  • color-supported: not-supported

some guys ask me to use snmp4j or LPR to know the status.

i wrote an application using snmp. i couldn't success on it. You can find the code form following link snmp application. In this code(Line no 38 SNMPManager client = new SNMPManager("udp:127.0.0.1/161"); we need to give the ip address of the printer. so i gave tcp/ip:127.0.0.1/161) i got an exception Exception in thread "main" java.lang.IllegalArgumentException: Address type tcp/ip unknown, i expecting a help to solve this.

user2255885
  • 327
  • 3
  • 4
  • 13
  • 1
    javax.print talk to the host running the JVM. SNMP talks to the printer itself. You will most likely get the best by talking to the printer itself, but this is not standardized. – Thorbjørn Ravn Andersen Apr 24 '13 at 10:16
  • http://stackoverflow.com/questions/15923863/get-printer-status-using-snmp-oid – Lex Li May 14 '13 at 03:24
  • Hi user2255885, did you solved the problem?. I am also want the same type of application that you explained. Thanks... – user4232 Jun 04 '13 at 06:09

1 Answers1

1
PrintService printer = PrintServiceLookup.lookupDefaultPrintService();
AttributeSet att = printer.getAttributes();

for (Attribute a : att.toArray()) {
    String attributeName;
    String attributeValue;

    attributeName = a.getName();
    attributeValue = att.get(a.getClass()).toString();

    String gh = (attributeName + " : " + attributeValue);

    if (gh.equals("printer-is-accepting-jobs : not-accepting-jobs")) {
        JOptionPane.showMessageDialog(rootPane, "Printer Not Available");
    }

    if (gh.equals("queued-job-count : 0")) {
        JOptionPane.showMessageDialog(rootPane, gh);
    }

    System.out.println(gh);
}
nhahtdh
  • 55,989
  • 15
  • 126
  • 162