The SimpleBook program uses a Book to manage
two page painters: PaintCover is used for the cover page,
and PaintContent is used for the content page. The cover
page is printed in landscape mode, whereas the content page is printed
in portrait mode.
Once the Book is created, pages are added to it with the
append method. When you add a page to a Book,
you need to specify the Printable and
PageFormat to use for that page.
// 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(), job.defaultPage());
bk.append(new PaintContent(), landscape);
// Pass the book to the PrinterJob
job.setPageable(bk);
The setPageable method is called on the
PrinterJob to tell the printing system to use the
Book to locate the appropriate rendering code.
You can find the full program in
SimpleBook.java.