Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting and printing to a printer in Java

Tags:

java

printing

Is there an easy way in Java to do the following?

  1. Connect to a printer (will be a local printer and the only printer connected to the machine).
  2. Print pages that are 2 pages in 2 different printer trays.
  3. Get the current print queue count, i.e. I have 100 items to print and 34 have been currently printed, the printer queue should now read 66.
like image 590
user789122 Avatar asked Jun 08 '11 12:06

user789122


People also ask

How do you print output in Java?

Java System. out. println() is used to print an argument that is passed to it.

What code is used for printing on the screen in Java?

In Java, System. out. println() is a statement which prints the argument passed to it. The println() method display results on the monitor.

Can I print image in Java?

The Java Printing API enables applications to: Print all AWT and Java 2D graphics, including composited graphics and images.


2 Answers

Some quick hints:

  • print from java: see A Basic Printing Program

  • status of printing job: you might be able to get something useful by using a PrintJobListener:

Implementations of this listener interface should be attached to a DocPrintJob to monitor the status of the printer job. These callback methods may be invoked on the thread processing the print job, or a service created notification thread. In either case the client should not perform lengthy processing in these callbacks.

like image 147
MarcoS Avatar answered Sep 27 '22 19:09

MarcoS


A very good printing tutorial: http://download.oracle.com/javase/tutorial/2d/printing/index.html

Also check answers to my question about printers, the Printer Job API is what are you looking for, but checking this out will also help:

How to Send JTable data to Print Job from Java Application?

like image 44
Saher Ahwal Avatar answered Sep 27 '22 20:09

Saher Ahwal