简体   繁体   中英

Additional page for Jasper reports

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?

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.

The sample

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM