Printing |
When you need more control over the individual pages in a print job, you can use a pageable job instead of a printable job. The simplest way to manage a pageable job is to use theBook
class, which represents a collection of pages.Example: SimpleBook
The
SimpleBook
program uses aBook
to manage two page painters:PaintCover
is used for the cover page andPaintContent
is used for the content page. The cover page is printed in landscape mode, while the content page is printed in portrait mode.Once the
Book
is created, pages are added to it with theappend
method. When you add a page to aBook
, you need to specify thePrintable
andPageFormat
to use for that page:The// In the program's job control code... // Get a PrinterJob PrinterJob job = PrinterJob.getPrinterJob(); // Create a landscape page format PageFormat landscape = job.defaultPage(); landscape.setOrientation(PageFormat.LANDSCAPE); // Set up a book Book bk = new Book(); bk.append(new PaintCover(), landscape); bk.append(new PaintContent(), job.defaultPage()); // Pass the book to the PrinterJob job.setPageable(bk);setPageable
method is called on thePrinterJob
to tell the printing system to use theBook
to locate the appropriate rendering code.Here's the complete program:
SimpleBook.java
.
Printing |