Solved

Controlling the printers from a java application

Posted on 2004-04-18
3
710 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

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

867 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

22 Experts available now in Live!

Get 1:1 Help Now