In addition to generating and viewing reports, Jaspersoft Studio allows you to export reports into many formats, including PDF, XLS, HTML and others. In this tutorial we will go over the steps necessary to export a generated report using Jaspersoft Studio. We'll use the report generated during the tutorial Designing a Report with Jaspersoft Studio.
Compiling the Report
When you switch on the Preview tab in the designer bottom bar, Jaspersoft Studio performs a set of operations to create the final report. The first operation compiles the JRXML source file in a Jasper file. This first step can fail if the elements are not correctly positioned (for example, if an element is placed outside of a band), or if an expression in the report has errors and cannot be compiled.
If the compilation runs successfully, the produced Jasper file is loaded and filled using the active connection or data source. This second operation can also lead to errors. This can happen if the referenced database is not active, an invalid query has been provided, or a null field produced an error in an expression during the filling process. If all operations complete without error, the report is displayed in the integrated viewer. Errors are shown in the Report State window, after clicking the Errors button, as shown in the following image:
If errors occur during the compilation, the tab changes from Preview to Design.
Preview and Exporting
If the compilation completes and there are no errors in the file, the preview is shown. From there you can browse the generated report and change its visualization, change the data source or export the report. Note that after changing the data source the report is recompiled automatically. You can also change the preview format and save the report in different formats.
In the image you can see that there is a green Play button. Clicking this button forces the report to be regenerated; it should be used when a subreport changes, or when you want to execute the report with different input parameters. When you set a preview format, the report is automatically regenerated in the chosen format, and the corresponding viewer application is opened - a PDF viewer or OpenOffice, for example.