Change paper and page settings with Java APIs
The default paper settings for a report are specified in the .4rp file. Override the defaults in your report program with Java reporting APIs.
Each report design document includes details about the page orientation, the page size of the report, and the report margins. These values are set when a report is first created, and can be altered by the report designer. See Specify the paper settings of a report for details about setting these values within the report design document (.4rp).
In the Java report application, you can override these report page and paper settings, thanks to the order of precedence for paper settings:
Paper settings order of precedence
- In the report application using reporting APIs.
- In the report design document (.4rp).
- GRW default values.
Change the page height and width
FourRpLayouter
or PXMLLayouter
objects.FourRpLayouter report = new FourRpLayouter(designFile, renderer);
// Set the page height
report.setPageLength("11inch");
report.setPageWidth("8.5inch");
Change the report margins
FourRpLayouter
or PXMLLayouter
objects.
FourRpLayouter report = new FourRpLayouter(designFile, renderer);
// Set the page margins
report.setTopMargin("5mm");
report.setBottomMargin("5mm");
report.setLeftMargin("4mm");
report.setRightMargin("4mm");
Set page orientation
The initial report size is set in the report design document (.4rp). In the report application, use Java reporting APIs to change the orientation forFourRpLayouter
or PXMLLayouter
objects. There
is no method for changing the page orientation; you change the height and width of the paper to
create a portrait or landscape orientation.In this example, assume the initial report is a
standard A4 portrait report. To change it to an A4 landscape report, use the
setPageLength()
and setPageWidth()
methods.
FourRpLayouter report = new FourRpLayouter(designFile, renderer);
// Change page orientation
report.setPageLength("a4width"); // height is now width
report.setPageWidth("a4length"); // width is now height