Solved

Checking printer status using Java

Posted on 2007-04-04
3
3,643 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 26

Accepted Solution

by:
mrcoffee365 earned 500 total points
Comment Utility
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
Comment Utility
Thanks for your help - it's always good to get a second opinion!
0
 
LVL 26

Expert Comment

by:mrcoffee365
Comment Utility
Glad to help.  Good luck on your project.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
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 …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now