Checking printer status using Java

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
bemusedalienAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
mrcoffee365Connect With a Mentor Commented:
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
 
bemusedalienAuthor Commented:
Thanks for your help - it's always good to get a second opinion!
0
 
mrcoffee365Commented:
Glad to help.  Good luck on your project.
0
All Courses

From novice to tech pro — start learning today.