Solved

Controlling the printers from a java application

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Books that can get me started on JAVA 2 56
topping2 challenge 13 61
word0 challenge 4 54
wordappend challenge 8 85
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

762 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

18 Experts available now in Live!

Get 1:1 Help Now