Reputation: 1339
I would like to add a Disclaimer page for every report generated with Jasper. This will be a page with static text and is the same for every report. But it needs to be generated as a last or the first page of the report. Is there a way of creating such a solution?
Upvotes: 2
Views: 2329
Reputation: 22857
In case using Java you can use Batch Mode Export. You can set the list of JasperPrint with help of JASPER_PRINT_LIST parameter to generate one report from the several templates.
You can add report with disclaimer to all your reports. You don't need to modify the jrxml files.
For example we have report (singleReport1.jrxml) and disclaimer for it (disclaimer.jrxml).
The report jrxml file is:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="singleReport1" language="groovy" pageWidth="297" pageHeight="421" whenNoDataType="AllSectionsNoDetail" columnWidth="257" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<title>
<band height="175" splitType="Stretch">
<staticText>
<reportElement x="8" y="46" width="241" height="83"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14"/>
</textElement>
<text><![CDATA[The First Report]]></text>
</staticText>
</band>
</title>
</jasperReport>
And the disclaimer code is:
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="disclaimer" language="groovy" pageWidth="297" pageHeight="421" whenNoDataType="AllSectionsNoDetail" columnWidth="257" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<title>
<band height="175" splitType="Stretch">
<staticText>
<reportElement x="8" y="46" width="241" height="83"/>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font size="14"/>
</textElement>
<text><![CDATA[The disclaimer]]></text>
</staticText>
</band>
</title>
</jasperReport>
The design in iReport for the first report is:
And the design for the disclaimer page is:
The Java code:
public static void testReport() throws JRException {
JasperReport jasperReport1 = JasperCompileManager.compileReport(reportSourceReport1);
JasperReport jasperDisclaimer = JasperCompileManager.compileReport(reportSourceDisclaimer);
JasperPrint jasperPrintReport1 = JasperFillManager.fillReport(jasperReport1, null, new JREmptyDataSource());
JasperPrint jasperPrintDisclaimer = JasperFillManager.fillReport(jasperDisclaimer, null, new JREmptyDataSource());
List<JasperPrint> jasperPrints = Lists.newArrayList();
jasperPrints.addAll(Arrays.asList(jasperPrintReport1, jasperPrintDisclaimer));
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrints);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, fileName);
exporter.exportReport();
}
The result will be (the pdf file opened in Adobe Reader):
Notes:
More info about Batch Mode Export
Upvotes: 6
Reputation: 1341
You can add a summary band; it will be displayed at the end of your report. If you're laying out your report in iReport, right-click the summary band in the Report Inspector and add it to your report, then click on the report name in the Report Inspector to open the Properties window. Click the Summary on a new page check box.
If you're coding this yourself, it looks like:
<jasperReport xmlns="..." isSummaryNewPage="true">
...
<summary>
<band height="50">
...
</band>
</summary>
Upvotes: 1