How to split to new page when isIgnorePagination

jasper-reports

Using Jaspersoft studio 6.2.

A main report with detail and summary bands. A sub report in the summary band of the main report. The main report itself (when without the subreport) will split into two pages, so I checked isIgnorePagination and the main report (when without subreport) comes out as single page.

The subreport itself split to 9 pages by default, when I checked isIgnorePagination it comes out as one single page. Fine. When I put the subreport in the main report with all the settings above, it comes out as one single page. How can I make the main report in one page and subreport in another page (so two pages in total)?

EDIT

Tried break component, it works but there is still a problem. The page height of the main report has to be set to be big enough to include both main report and subreport, otherwise there will be more than 2 pages, but that will leave too much blank at the bottom of the main report. Below is an example to show what I meant.

main report:

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  -->
    <!-- 2016-04-26T16:13:43 -->
    <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="test11" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ce9d78e1-7194-4754-aaf9-93e871d2a5cf">
        <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="datamart"/>
        <property name="com.jaspersoft.studio.unit." value="pixel"/>
        <queryString>
            <![CDATA[select 1 as a
    union all select 2 as a]]>
        </queryString>
        <field name="a" class="java.lang.Integer"/>
        <variable name="Total" class="java.lang.Integer" calculation="Sum">
            <variableExpression><![CDATA[$F{a}]]></variableExpression>
        </variable>
        <background>
            <band splitType="Stretch"/>
        </background>
        <columnHeader>
            <band height="50">
                <staticText>
                    <reportElement x="54" y="0" width="100" height="30" uuid="e9116c0f-c827-4cb3-95d1-9155f4be7cb7"/>
                    <text><![CDATA[a]]></text>
                </staticText>
            </band>
        </columnHeader>
        <detail>
            <band height="49" splitType="Stretch">
                <textField>
                    <reportElement x="50" y="10" width="100" height="30" uuid="79fa53fa-48e2-43d0-96a4-0cda54e95c25"/>
                    <textFieldExpression><![CDATA[$F{a}]]></textFieldExpression>
                </textField>
            </band>
        </detail>
        <summary>
            <band height="297" splitType="Stretch">
                <textField>
                    <reportElement mode="Opaque" x="52" y="16" width="100" height="30" backcolor="#C4E5F6" uuid="2a393151-947e-4f1d-ab24-e456ce56bd19"/>
                    <textFieldExpression><![CDATA[$V{Total}]]></textFieldExpression>
                </textField>
                <subreport>
                    <reportElement x="62" y="97" width="200" height="200" uuid="b342cbae-597b-4ca5-b00d-3a4d047910f8"/>
                    <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    <subreportExpression><![CDATA["test12.jasper"]]></subreportExpression>
                </subreport>
                <break>
                    <reportElement x="0" y="60" width="619" height="1" uuid="ccc2155d-6a2e-4c23-a972-88bb871cb17d"/>
                </break>
            </band>
        </summary>
    </jasperReport>

sub report

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0  -->
    <!-- 2016-04-26T16:14:10 -->
    <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="test12" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="3601f813-f6da-4105-a4d8-5c1ee1dd54d4">
        <property name="com.jaspersoft.studio.data.sql.tables" value=""/>
        <property name="com.jaspersoft.studio.data.defaultdataadapter" value="datamart"/>
        <queryString>
            <![CDATA[select 10 as col 
    union all select 20  as col]]>
        </queryString>
        <field name="col" class="java.lang.Integer"/>
        <variable name="total" class="java.lang.Integer" calculation="Sum">
            <variableExpression><![CDATA[$F{col}]]></variableExpression>
        </variable>
        <background>
            <band splitType="Stretch"/>
        </background>
        <columnHeader>
            <band height="61" splitType="Stretch">
                <staticText>
                    <reportElement x="73" y="0" width="100" height="30" uuid="5f2cfa26-c7ab-413e-94cf-80c1f1b288eb"/>
                    <text><![CDATA[col]]></text>
                </staticText>
            </band>
        </columnHeader>
        <detail>
            <band height="125" splitType="Stretch">
                <textField>
                    <reportElement x="73" y="90" width="100" height="30" uuid="3af983fb-00e2-4bb9-9e91-2d2214ca95d7"/>
                    <textFieldExpression><![CDATA[$F{col}]]></textFieldExpression>
                </textField>
            </band>
        </detail>
        <summary>
            <band height="49" splitType="Stretch">
                <textField>
                    <reportElement mode="Opaque" x="74" y="19" width="100" height="30" backcolor="#FFCC33" uuid="b333fb92-8aa8-4f00-9a1a-db24657d5521"/>
                    <textFieldExpression><![CDATA[$V{total}]]></textFieldExpression>
                </textField>
            </band>
        </summary>
    </jasperReport>

There is a break in the main report, this works fine, 2 pages one for the main report and one for the sub report, but the main report leaves too much blank at the bottom, if I reduce the height of the main report (e.g. to 400 pixel), there will be more than 2 pages. Is it possible to get just 2 pages without too much blank?

Best Answer

To achieve different size for each page you need to use the attribute, isIgnorePagination="true" on the jasperReport tag.

When isIgnorePagination is true the break element is ignored by default you need to enabled it by setting this property net.sf.jasperreports.page.break.no.pagination to apply

ignore - page breaks are ignored in non paginated reports. (default)
apply -  page breaks are honoured in non paginated reports.

<property name="net.sf.jasperreports.page.break.no.pagination" value="apply"/>

This will enable the break component and you can manuale break to new page using

<break> 
    <reportElement x="0" y="0" width="100" height="1" uuid="604c65b5-1127-4874-a63c-9b1a98dbf25c"/>
</break>
Related Topic