CONTENTS | PREV | NEXT | Java 2DTM API |
You can allow the user to select the paper size and orientation by displaying a page setup dialog. To do this, you call Toolkit.setupPage.
import java.lang.*; import java.awt.*; import java.awt.print.*; public class PageFormatPrint { public static void main(String[] args) { Toolkit tk = Toolkit.getDefaultToolkit(); // Create a new book Book book = new Book(); // Create a PageFormat and display the Page Setup dialog PageFormat pageFormat = tk.setupPage(new PageFormat()); // Add two pages to the book that use the same page format and // painter book.append(pageFormat, new NumberPainter(), 2); /* Get a print job from the graphics environment and * tell it to print our book of three pages. */ PrintJob job = GraphicsEnvironment.getLocalGraphicsEnvironment().getPrintJob(); if(job.setupJob(book) == true){ job.print(book); } System.exit(0); }