Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Controlling the printers from a java application

Posted on 2004-04-18
3
Medium Priority
?
744 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
[X]
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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

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…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
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 …
Suggested Courses

730 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