Sample Reference - Schema Reference - Configuration Reference - API (Javadoc)
|
|
|
|
JasperReports - No Page Break Sample (version 4.0.1) | ![]() |
|
|
|
Main Features in This Sample | |
| Suppress Pagination |
![]() | ![]() | ![]() | ![]() |
|
|
top | |||||
|
|||||
![]() | Suppress Pagination | Documented by Sanda Zaharia | |||
|
|||||
| Description / Goal |
| How to suppress pagination in generated documents. | ||
| Since |
| 1.0.1 | ||
|
|||||
|
The isIgnorePagination Flag
Usually JasperReports generates page-oriented document layouts: each document is a collection of pages having the same width, height, and page orientation. However, if needed, multiple documents with particular page settings can be concatenated to produce a single document output with different page layouts, using the batch export facility. In the case where no batch export is implied, all document pages share the same page settings, and they are by default separated by page breaks. At export time each exporter has its own way to handle the page break element in order to make visible the page separation. But there are situations, especially for web-oriented applications, where pagination is irrelevant and it causes the document to be displayed improperly. For instance, when exporting documents to HTML format, one might prefer to display it as a continuous scrollable page rather than a succession of pages separated by visible empty spaces. Or, when exporting to Excel in a single sheet document, a layout without visible page breaks would be preferred. This is why the engine needs to be instructed how to handle page breaks in various situations. A possibility would be to completely ignore the pagination, with no respect to the output document format. Responsible for this kind of approach is the isIgnorePagination flag property. It can be found among the
<jasperReport/> element attributes:
<jasperReport ... isIgnorePagination="true" ...>
When isIgnorePagination is set to true , the report-filling engine will
generate the document on a single, very long page. Running the generated report to any output format,
a single page document will be visualized.
While this is the desired behavior for some document types, such as HTML, XML or XLS, it's quite uncomfortably for documents with page-oriented layout (like PDF, DOCX, etc) to be displayed as single very long pages, without the possibility to navigate between pages. By default, isIgnorePagination is set to false . For various purposes this flag can be
overriden at report filling time using the optional built-in
IS_IGNORE_PAGINATION parameter.
Handling Page Breaks at Export Time When isIgnorePagination is true the report will be generated in a single page.
And this layout will be irreversible. The resulting page can no more be fragmented back into multiple sections
at runtime.
Therefore, using a isIgnorePagination="true" attribute works properly if the report will be definitely
printed out in flow-oriented document layouts. In the case of multiple output document layout, the best choice is
to let the pagination being handled at export time, each exporter providing its own handling mode.
In order to accomplish this, one have to let the isIgnorePagination with its default value
(ie false ). At fill time the document will be generated as multiple pages document. Then, at export time,
the exporter could decide whether to print out the document as multipage, or to concatenate all pages into a single one,
by suppressing all empty space between pages.
Handling Page Breaks with HTML Exporter When a multipage document gets exported into HTML format there are three possibilities to configure its layout:
JasperReports provides several dedicated exporters to export documents in Excel formats. All of them generate Excel-compatible documents organized as workbooks which store inside one or more separated sheets. Because Excel documents are collections of sheets, one can consider that usually an Excel sheet is equivalent to a document page, and each XLS exporter should be able to translate a page content into an equivalent sheet content. Like in HTML, there are multiple possibilities to handle sheet breaks when exporting to Excel format:
Suppress Pagination Examples This sample works with the default value for the isIgnorePagination flag, which means that the document will be generated into separate pages.
Then, when the document gets exported, some exporters are instructed to suppress the pagination in specific ways.
In the NoPageBreakApp.java one can see how the export parameters responsible for page breaks handling are set. For the HTML exporter (see the html() method):
exporter.setParameter(JRHtmlExporterParameter.BETWEEN_PAGES_HTML, ""); exporter.setParameter(JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);And for XLS and XLSX exporters (see xls() and xlsx() methods)
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.FALSE); exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);For comparison, the IS_ONE_PAGE_PER_SHEET parameter was set to true for the JExcelApi exporter (see the jxl() method):
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE); exporter.setParameter(JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, Boolean.TRUE);Running the Sample Running the sample requires the Apache Ant library. Make sure that ant is already installed on your system (version 1.5 or later).
In a command prompt/terminal window set the current folder to demo/hsqldb within the JasperReports source project and run the > ant runServer command.
It will start the HSQLDB server shipped with the JasperReports distribution package. Let this terminal running the HSQLDB server.
Open a new command prompt/terminal window and set the current folder to demo/samples/charts within the JasperReports source project and run the > ant test view command.
It will generate all supported document types containing the sample report in the demo/samples/charts/build/reports directory.
Then the report will open in the JasperReports internal viewer. |
||||
|
|
© 2001-2010 Jaspersoft Corporation www.jaspersoft.com |