Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Checking printer status using Java

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb on wildfly 5 30
ejb mdb examples 1 6
Crystal Reports Licensing Questions 4 34
Need Help! Getting a syntax error and don't understand why 3 31
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This video teaches viewers about errors in exception handling.
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 …

809 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