Solved

Checking printer status using Java

Posted on 2007-04-04
3
3,762 Views
Last Modified: 2008-01-09
Hi Experts,
We have some developers working on a Java application under Windows XP for us. Part of this requires printing using a windows printer driver to control a specialist printer. This causes windows errors to pop up when a problem occurs but I want the application to handle all the errors as this application runs on a touch screen kiosk. Currently, they are monitoring the print spooler via the Java Virtual Machine and then trying to resolve issues by disabling the printer (and redirecting to the backup printer) and removing the print job.  However, I would have thought it would be better to check the printer status prior to printing (e.g online, paper out etc). They are telling me this is either extremely difficult or impossible as they would need to bypass the windows printer driver and talk directly to the printer. I would have thought you could get this information from the window printer driver? Is this possible using Java, or is it dependent on the specific implementation of the windows printer driver? Any hints would be appreciated and sample code would be even more appreciated!
Regards
Graham
0
Comment
Question by:bemusedalien
  • 2
3 Comments
 
LVL 27

Accepted Solution

by:
mrcoffee365 earned 500 total points
ID: 18852297
You can check the printer status before sending a print job (and your developers are right, this can be a tricky thing to do, sometimes OS-dependent and sometimes device-dependent), but you'll still have to handle the case of out of paper.  It's an event-driven system, and things happen which might not be under the control of the app.

Whether the Java Printer Service (or whatever they are using to communicate with the specialist printer you mention) can get a correct status flag from the printer will depend a lot on the printer itself.  It also depends on whether it is a network printer or a local printer.

If the API to the special printer will respond with an out of paper flag, then it will be possible to make Java calls to get that information.

However, if the "out of paper" flag is not returned as part of the standard printer driver for that printer, then the Java calls to communicate with the printer will have to be done with Java serial IO, as the developers said, somewhat bypassing the printer driver.  Java serial IO is considered quite difficult if you do not have programmers experienced with it.

This is the Java Print Service doc from Sun:
http://java.sun.com/javase/6/docs/technotes/guides/jps/index.html

Roedy Green's Java Glossary is always a good introduction to any Java topic:
http://mindprod.com/jgloss/printing.html

Point of Sale apps have to deal with this, so there is some discussion of how to handle it here:
http://www.javapos.com/devint.html

Sample code for checking out of paper:
http://www.starmicronics.com/printers/printers_pages/support/samples/javapos.txt

On Windows, there's more support in VB for handling serial device printers.  But that code is OS-dependent and relies on knowledge "below the covers."  Still, you could go that route and communicate with a COM object if you know that Windows is the only platform you plan to support.

That's why the Java printing code tends to be complex -- it is attempting to create a generalized API that is independent of the OS and the printer drivers, and that is more complicated than assuming a single OS and a single driver.
0
 

Author Comment

by:bemusedalien
ID: 18873276
Thanks for your help - it's always good to get a second opinion!
0
 
LVL 27

Expert Comment

by:mrcoffee365
ID: 18873872
Glad to help.  Good luck on your project.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet requestdispatcher include and forward differences 1 30
Windows 10 IE Certificate Issue 10 45
hibernate example using maven 12 41
null output 3 24
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question