Solved

Checking printer status using Java

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

932 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

10 Experts available now in Live!

Get 1:1 Help Now