Java Reference
In-Depth Information
javax.print.attribute : Defines classes and interfaces supporting the definition of sets of print-
ing attributes. For example, you can define a set of attributes required by a particular document
when it is printed, such as color output and two-sided printing.
javax.print.attribute.standard : Defines classes that identify a set of standard printing at-
tributes.
javax.print.event : Defines classes that identify events that can occur while printing and inter-
faces that identify listeners for printing events.
java.awt.print : Defines classes and attributes for expediting the printing of 2D graphics and
text.
The first four make up what is called the PrintServiceAPI . This allows printing on all Java platforms and
has facilities for discovering and using multiple printers with varying capabilities. Because in all probability
you have just a single printer available, I'm concentrating on explaining the classes and interfaces defined
in the java.awt.print package that carry out print operations on a given printer, and stray into classes and
interfaces from the other packages when necessary.
Four classes are defined in the java.awt.print package, and you use all of them eventually:
PrinterJob objects: Control printing to a particular print service (such as a printer or fax capab-
ility).
PageFormat objects: Define information about a page to be printed, such as its dimensions, margin
sizes, and orientation.
Paper objects: Define the size and printable area of sheets of paper.
Book objects: Define a multipage documents where pages may have different formats and require
different rendering processes.
The PrinterJob class drives the printing process. Don't confuse this with the PrintJob class in the
java.awt package — this is involved in the old printing process that was introduced in Java 1.1, and the
PrinterJob class now supersedes this. A PrinterJob object provides the interface to a printer in your en-
vironment, and you use PrinterJob class methods to set up and initiate the printing process for a particular
document. You start printing off one or more pages in a document by calling the print() method for the
PrinterJob object.
You'll get into the details of how you work with the other types of objects in the list a little later in this
chapter.
There are three interfaces in the java.awt.print package:
Printable : Implemented by a class to print a single page.
Pageable : Implemented by a class to print a multipage document, where each page may be printed
by a different Printable object. This allows pages in a document to have independent specifica-
tions, such as orientation and margin sizes.
PrinterGraphics : Declares a method for obtaining a reference to the PrinterJob object for use
in a method that is printing a page.
When you print a page, an object of a class that implements the Printable interface determines what is
actually printed. Such an object is referred to as a page painter . Figure 21-4 illustrates the basics of how the
printing process works.
FIGURE 21-4
 
 
Search WWH ::




Custom Search