View RSS Feed

Java AWT

Basic Printing Program

Rate this Entry
by , 03-07-2012 at 06:07 PM (742 Views)
Printing consists of following two parts:

Job Control: Following are part of job control.
  • Creating a print job
  • Associate it with printer
  • Specify no of copies
  • User print dialog interaction

Page Imaging: It includes drawing content to a page.
The java.awt.print package includes the classes to create a printer job and most other related classes are part of this package.
Java Code:
import java.awt.print.*;
PrinterJob job = PrinterJob.getPrinterJob();
Following code renders the content to the page.
class HelloWorldPrinter implements Printable  { ... }
job.setPrintable(new HelloWorldPrinter());
A print dialog is displayer in an application so that user can select different options. Following code is used to display this dialog.
Java Code:
boolean doPrint = job.printDialog();

Submit "Basic Printing Program" to Facebook Submit "Basic Printing Program" to Digg Submit "Basic Printing Program" to Submit "Basic Printing Program" to StumbleUpon Submit "Basic Printing Program" to Google