CONTENTS | PREV | NEXT Java 2D API


7.3 Printing in Landscape Mode

To print in landscape mode, the page orientation must be set to LANDSCAPE in the PageFormat. To do this, you call setOrientation:

pageFormat.setOrientation(PageFormat.LANDSCAPE);
In the following example:


7.3.1 SimpleLandscape

import Java.lang.*;
import Java.awt.*;
import Java.awt.print.*;
public class SimpleLandscape {
public static void main(String[] args) {
/* Create a new book with two landscape pages.
*/
Book book = new Book();
PageFormat pageFormat = new PageFormat();
pageFormat.setOrientation(PageFormat.LANDSCAPE);
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();
job.print(book);
System.exit(0);
}
}


CONTENTS | PREV | NEXT
Copyright © 1997-1998 Sun Microsystems, Inc. All Rights Reserved.