CONTENTS | PREV | NEXT | Java 2D API |
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:
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);
}
}