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

Controlling the printers from a java application

Posted on 2004-04-18
3
714 Views
Last Modified: 2008-02-01
Hi,

Will like to write an application which is to work in a Windows environment which will allow us to control the networked printers.  Are there any existing java apis, packages or products which we can use.   The application needs to be able to:

  a.  Send print documents to the printer to print
  b.  Poll the status of the printer, i.e. look at the print spool
  c.  Issue commands to the printer to cancel print jobs

Thanks.
0
Comment
Question by:eng80327
3 Comments
 

Accepted Solution

by:
johnknapp earned 125 total points
ID: 10867114
Need some more information on this,

1) Are the printer's in question shared in windows via print sharing? i.e. are all the printer's in question available via the printers folder in windows?

If so you can do all except b using the javax.print.*, javax.print.attribute.*, javax.print.attribute.standard.* packages.  

PrintService[] printers = PrintServiceLookup.lookupPrintServices(DocFlavor flavor, AttributeSet attributes); // if you supply null for both params you get all printers supported under standard windows printing.

Then query the printers array one by one, using a print request attribute

create a print job on the chosen PrintService

DocPrintJob job = printers[0].createPrintJob(); // or whatever print service you chose to execute your printing

to cancel the job, first you have to check if it can be cancelled, to do this it is easiest to check if the job returned is an instance of CancelablePrintJob
if (job instanceof CancelablePrintJob) {
    // you can cancel the job by calling ((CancelablePrintJob) job).cancel();
} else {
    // you can't cancel the job
}

if you want you can also register listeners for the job

and then call job.print(Doc doc, PrintRequestAttributeSet attributes); // this does the actual printing

print spooler, you could implement your own if only your application will be printing to the printers in question or you don't care what other applications are printing to the printers by registering listeners for all print jobs you send to the printers.

Also the javax.print packages are fairly well documented, and an excellent book on the javax.print packages is

core java 2 Volume II - Advanced Features by Cay S. Horstman and Gary Cornell - Prentice Hall

Chapter 7 Advanced AWT

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tomcat not starting 6 64
servlet example 11 49
java example issue 3 20
Java 8 to Java 6 8 20
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.

792 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