Java Reference
In-Depth Information
After you have a PageFormat object, you can modify the orientation of the page by calling its setOri-
entation() method as you know, the possible values for the argument being LANDSCAPE , PORTRAIT , or
REVERSE_LANDSCAPE . The PageFormat class defines several methods to retrieve information about the pa-
per — you have seen that you can get the position and size of the printable area on the page, for instance, by
calling the getImageableX() , getImageableY() , getImageableWidth() , and getImageableHeight()
methods. You also have getWidth() and getHeight() methods in the PageFormat class that return the
overall width and height of the page, respectively. These are all properties of the paper itself, which is rep-
resented by an object of the java.awt.print.Paper class that is associated with a PageFormat object. You
can also work with the Paper object for a PageFormat object directly.
Dealing with Paper
The Paper class encapsulates the size of the paper and the size and position of the printable area on the page.
The default constructor for the Paper class creates an American letter-sized sheet with one-inch margins
— the printable area being the area inside the margins. You can change the size of the paper by calling the
setSize() method for the Paper object, as you see in a moment.
Rather than creating an independent Paper object, you would normally retrieve a reference to the Paper
object for a PageFormat object by calling its getPaper() method. If you then want to change the size of
the paper, or the printable area — the page margins, in other words — you can call the setSize() or the
setImageableArea() method for the Paper object. You can restore the paper details by passing an object of
type Paper back to the PageFormat object by calling its setPaper() method with a reference to the Paper
object as the argument.
The setSize() method for a Paper object has two parameters of type double that specify the width and
height of the paper in units of 1/72 of an inch. If you use A4 paper, you could specify the size of the paper
for a PageFormat object with the following statements:
Search WWH ::




Custom Search