21.4. Printing in Java
Printing is always a messy business—inevitably so, because you have to worry about tedious details such as the size of a page, the margin sizes, and how many pages you're going to need for your output. As you might expect, the process for printing an image is different from printing text, and you may also have the added complication of several printers with different capabilities being available, so with certain types of documents you need to select an appropriate printer. The way through this is to take it one step at a time. Let's understand the general principles first.
There are five packages dedicated to supporting printing capabilities in Java:
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. |
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 ...
Get Ivor Horton's Beginning Java™ 2, JDK™ 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.