|
The main header and footer methods are:
setLeftHeader (java.lang.Object leftHeader): Sets the left header using either a String or JLabel. There are similar methods for setCenterHeader and setRightHeader, as well as for setLeftFooter , setCenterFooter, and setRightFooter.
setHeaderStyle (int style): Sets header style (BOX, LINE, or NONE). There is a similar method for setFooterStyle.
setHeaderFont (java.awt.Font font): Sets the font for printing the headers when these are specified using a String. There is a similar method for setFooterFont.
setGapAboveFooter (double gapAboveFooter): Sets the gap between the bottom of the last line of body and the top of the footer in inches. There is a similar method for setGapBelowHeader.
Any of the above methods can be specified with an additional argument to separately control whether the settings apply to the first page vs. the remaining pages, for example:
setLeftHeader (int which, java.lang.Object leftHeader): Sets the left footer for either page 1 (FIRST) or pages 2...n (REST) using a String or JLabel.
Margins
You can control the top, bottom, left, and right margins of your document. These are specified from the edge of the page, but since most printers have an "unprintable margin" area, the actual margin used will not be less than the unprintable margin.
setTopMargin (double topMargin): Sets the top margin (above header) in inches from the edge of the page. There are similar methods for setBottomMargin, setLeftMargin , and setRightMargin.
Orientation and scale
You can control the printing orientation on the page using the following method:
setOrientation (int orientation): Sets page orientation (portrait vs. landscape vs. reverse landscape).
You can control the scale with which pages are printed by calling the method:
setScale (double scale): Sets magnification or minification scaling factor.
Setting the value of scale to 1.0 results in unscaled (100%) printing. Setting this value to greater than 1.0 or less than 1.0 will cause magnification or minification, respectively.
Reading and writing PageFormat instances
J2Printer prints using margin, paper size, and orientation values set using the above methods. As a convenience for developers who need a standard Java PageFormat instance with the equivalent margins, paper size, and orientation, we have provided methods to convert between J2Printer's values and PageFormat. These can be particularly useful when working with externally-defined Pageables. The methods are:
getPageFormat (): Method for creating a PageFormat instance based on the J2Printer margins, paper size, & orientation.
setPageFormat (java.awt.print.PageFormat pageFormat): Method for setting the J2Printer margins, paper size, & orientation based on the specified PageFormat.
Global vs. local values
Each of the individual J2PrinterWorks Pageable components such as J2TextPrinter has a parallel set of methods for setting the headers, footers, margins, orientation, and scale. The J2Printer methods set the global (overall, default) values for these properties, which are the values that will be used unless a given Pageable sets it own local value. For example:
J2Printer printer = new J2Printer();
printer.setLeftFooter("Overall footer"); // set global properties
J2TextPrinter textPrinter = new J2TextPrinter(yourJTextPane);
J2TablePrinter tablePrinter = new J2TextPrinter(yourJTable);
textPrinter.setLeftFooter("My footer"); // set properties for this Pageable
printer.addPageable(textPrinter);
printer.addPageable(tablePrinter);
printer.print();
In this case, "My footer" will be the value used on the textPrinter pages, whereas "Overall footer" will be the value used on the tablePrinter pages (and any other Pageables in the document that do not specify their own values).
« »
|