Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Controlling the printers from a java application

Posted on 2004-04-18
3
Medium Priority
?
757 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
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 tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses

927 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