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.
In the following example:
-
NumberPainter implements the Printable interface to draw page numbers on each page.
-
PageFormatPrint is identical to SimplePrint, except that setupPage is called to display the page setup dialog and set the page format.
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);
}
CONTENTS | PREV
| NEXT
Copyright © 1997-1999 Sun
Microsystems, Inc. All Rights Reserved.