Java Reference
In-Depth Information
Package
Description
javax.print
Defines classes and interfaces that enable you to determine what
printers are available and what their capabilities are. It also enables
you to identify types of documents to be printed.
javax.print.
attribute
Defines classes and interfaces supporting the definition of sets of
printing 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, for instance.
javax.print.
attribute.standard
Defines classes that identify a set of standard printing attributes.
javax.print.event
Defines classes that identify events that can occur while printing
and interfaces 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 of these packages make up what is called the
Print Service API
that was added to Java in
SDK 1.4. This allows printing on all Java platforms and has facilities for discovering and using multiple
printers with varying capabilities. Since in all probability you have just a single printer available, we will
concentrate in the first instance on understanding 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.
There are four classes in the
java.awt.print
package and we will be using all of them eventually:
PrinterJob
An object of this class type controls printing to a particular print
service (such as a printer or fax capability).
PageFormat
An object of this class type defines the size and orientation of a
page that is to be printed.
Paper
An object of this class type defines the size and printable area of a
sheet of paper.
Book
An object of this class type defines a multipage document where
pages may have different formats and require different rendering
processes.
The
PrinterJob
class here 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 introduced in Java 1.1 and the
PrinterJob
class now supersedes this. A
PrinterJob
class object provides the interface to a printer
in your environment, 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.