Java Reference
In-Depth Information
Creating PageFormat Objects
As we saw earlier, you can get the default PageFormat object for the print service you are using by calling
the defaultPage() method for the PrinterJob object. The default PageFormat class constructor can
also be used to create an object that is portrait oriented but in this case you have no guarantee that it is
compatible with the current print service. A PageFormat object encapsulates information about the size of
the paper and the margins, in effect, so the object produced by the default constructor is unlikely to
correspond with your printer setup. If you want to go this route, you can pass a reference to a PageFormat
object to the validatePage() method for a PrinterJob() object. For example:
// Object for current printer
PrinterJob printJob = PrinterJob.getPrinterJob();
// Validated page
PageFormat pageFormat = printJob.validatePage(new PageFormat());
Note that the validatePage() method does not return the same reference that is passed as an
argument. The method clones the object that was passed to it and returns a reference to the clone,
which will have been modified if necessary to suit the current printer. Since it does not modify the
object in place, you always need to store the reference that is returned.
getImageableX(), getImageable()
getWidth()
0.0
top margin
getImageableWidth()
Length and Width are in
units of 1/72 of an
inch
getImageHeight()
bottom margin
PageFormat Methods and the Paper
Search WWH ::




Custom Search