JasperReports Ultimate Guide - Sample Reference - Schema Reference - Configuration Reference - API (Javadoc)

JasperReports - Batch Export Sample (version 4.6.0)


Shows how multiple reports could be concatenated during export.

Download All Sample Source Files
Browse Sample Source Files on SVN


Main Features in This Sample

Exporting Multiple Reports into a Single Output File (Batch Export)


top

Exporting Multiple Reports into a Single Output File (Batch Export)Documented by Sanda Zaharia


Description / Goal
Several reports can be exported together to form a single resulting document.

Since
0.6.0


Exporter Input

The input data for an exporter comes in the form of one or more JasperPrint documents that must be exported to some other document format. These JasperPrint objects may be already in memory, come from the network through an input stream, or reside in files on disk.
An exporter should be able to handle such a wide range of document sources. In fact, all the exporter implementations that are shipped inside the library already do this. They all extend the net.sf.jasperreports.engine.JRAbstractExporter class, which holds all the logic for dealing with the source documents that need to be exported inside its defined setInput() method.

Batch Mode Export

The first thing an exporter needs to know is whether it is acting on a single JasperPrint document or a list with several such generated documents. Exporting multiple JasperPrint objects to a single resulting document is called batch mode exporting.
Not all exporters can work in batch mode, but those that do first look into the supplied parameter values to see whether a java.util.List of JasperPrint object has been supplied to them using the JASPER_PRINT_LIST exporter parameter. If so, the exporter loops through this list of documents and produces a single document from them.
If the exporters act on a single document, then they check whether a value is supplied to the JASPER_PRINT parameter, representing a single in-memory JasperPrint document that must be exported. If no value is found for this parameter, then the input for the exporter is a single JasperPrint document to be loaded from an input stream, an URL, a file object, or a file name. The exporter checks the following exporter parameters in this exact order, stopping at the first that has a non-null value: INPUT_STREAM, INPUT_URL, INPUT_FILE, and INPUT_FILE_NAME. If it does not find any of these parameters being set, then the exporter throws an exception telling that no input source was set for the export process.

Batch Mode Bookmarks

When several JasperPrint documents must be concatenated in the same PDF file by batch export, you can introduce PDF bookmarks in the resulting PDF document to mark the beginning of each individual document that was part of the initial document list.
These bookmarks have the same name as the original JasperPrint document as specified by the jasperPrint.getName() property. However, users can turn on and off the creation of those bookmarks by setting the IS_CREATING_BATCH_MODE_BOOKMARKS exporter parameter to Boolean.TRUE or Boolean.FALSE. The exporter does not create such bookmarks by default.

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/samples/batchexport 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/batchexport/build/reports directory.
Then the report will open in the JasperReports internal viewer.



© 2001- Jaspersoft Corporation www.jaspersoft.com