How to Check Printer Status in Java

Written by jeff grundy Google
  • Share
  • Tweet
  • Share
  • Email

Java is a powerful, cross-platform programming language that allows developers to create useful and engaging Web applications in a relatively short period. When developing an application, you might want to offer a user the ability to print Web forms or data sheets from their browser. Before executing a print command, however, your application should be able to check the status of the printer and ensure that it is online and in use by another process or program.

Skill level:

Things you need

  • Java compatible Integrated Development Environment application (i.e. Netbeans or Eclipse)

Show MoreHide


  1. 1

    Launch the Integrated Development Environment application on your computer. Click "File/Open" to browse to the Java application file to which you want to add print functions. Open the file.

  2. 2

    Click "File/New/Class" or "File/Create/Class" menu option on the tool bar. Wait for a blank "Class" document window to appear. Click "File/Save" and then save the new class file as "" or something similar. Just be sure to use the ".java" extension.

  3. 3

    Copy and paste the following code into the document window to define the new class object:

    public class StatusofPrinterReport {

    public static void main(String[] args) { 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();

    System.out.println(attributeName + " : " + attributeValue);


  4. 4

    Click "File/Save" on the IDE menu tool bar. Close the "Class" document viewer. The Java application can now request the status of the printer.

  5. 5

    Enter the following text in another module or class in your application to initiate the status request of the printer.

    StatusofPrinterReport obj=new StatusofPrinterReport();


Tips and warnings

  • When called, StatusofPrinterReport class returns the following information to the application:
  • printer-name: name as listed in the operating system
  • colour-supported: returns either "supported" or "unsupported"
  • printer-is-accepting-jobs: "accepting-jobs" or "not-accepting-jobs"
  • queued-job-count: "number of print jobs already in the print spooler"

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.