Specifying Headers and Footers in Printed Views

The following table lists various print methods and, for each, describes how headers and footers work when you use that method.

Method

Responsibility for Page Margins

PrintDialog.show

The PageSetupDialog class sets headers and footers.

ViewPrinter.print

You set headers and footers, as described in this topic. The view printer prints the headers and footers, starting at 18 pixels (by default) from the top and bottom of the page. You can change the header and footer margins using the setHeaderMargin and setFooterMargin methods on the view printer.

ViewPrinter.renderPage

You set header and footer properties, as described in this topic. The view printer prints the headers and footers, starting at 18 pixels (by default) from the top and bottom of the Dimension that represents the area into which the view is printed. You can change the header and footer margins using the setHeaderMargin and setFooterMargin methods on the view printer.

ViewPrinter.printPage

You are completely responsible for headers and footers. None of the properties that this topic describes has any effect.

Managing headers and footers

Each view printer has six HeaderAndFooterPainter objects, so you can display three headers and three footers on printed pages. To specify information for a header or footer, you get the appropriate HeaderAndFooterPainter and set its properties.

The constant that you pass in ViewPrinter.getHeaderAndFooterPainter determines which header or footer you get. The constants identify the location of the header or footer, as shown in the following table, which lists the constants and their descriptions.

Constant for getHeaderAndFooterPainter

Description

ViewPrinter.HEADER_LEFT

The left header. Left-aligned by default.

ViewPrinter.HEADER_CENTER

The center header. Centered by default.

ViewPrinter.HEADER_RIGHT

The right header. Right-aligned by default.

ViewPrinter.FOOTER_LEFT

The left footer. Left-aligned by default.

ViewPrinter.FOOTER_CENTER

The center footer. Centered by default.

ViewPrinter.FOOTER_RIGHT

The right footer. Right-aligned by default.

The content of the headers is specified by the ContentType property of the HeaderAndFooterPainter. The following table lists the valid constants for the ContentType property and their descriptions.

Constant for ContentType

Description

HeaderAndFooterPainter.NONE

No content

HeaderAndFooterPainter.DATE

The current date

HeaderAndFooterPainter.PAGE_NUMBER

The page number

HeaderAndFooterPainter.STRINGS

One or more strings, each on its own line

The following examples show how to specify headers and footers:

  1. Example: Using the print Method to Print a Graph

  2. Example: Using the print Method to Print a Crosstab

  3. Example: Printing the Same Logical Page of Two Different Views