如何使用jasperreports阻止最后的空白页面

时间:2017-08-09 14:39:13

标签: jasper-reports

我的报告左侧是包含动态内容的表格,右侧是包含静态固定大小文本的框架:

enter image description here

在下面找到jrxml源代码(我删除了表格的标题和三列以减小尺寸):

<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.3.1.final using JasperReports Library version 6.3.1  -->
<!-- 2017-08-10T11:19:14 -->
<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="WaterlevelForecastReport" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isSummaryNewPage="true" resourceBundle="messages" whenResourceMissingType="Empty" uuid="3cf70749-5058-4a53-ad3e-091553a6ed3e">
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
    <box>
        <pen lineWidth="0.5" lineColor="#000000"/>
        <topPen lineWidth="0.5" lineColor="#000000"/>
        <leftPen lineWidth="0.5" lineColor="#000000"/>
        <bottomPen lineWidth="0.5" lineColor="#000000"/>
        <rightPen lineWidth="0.5" lineColor="#000000"/>
    </box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF" hTextAlign="Center" vTextAlign="Middle" isBlankWhenNull="true" fontName="Arial" fontSize="8" isBold="false">
    <box>
        <pen lineWidth="0.5" lineColor="#000000"/>
        <topPen lineWidth="0.5" lineColor="#000000"/>
        <leftPen lineWidth="0.5" lineColor="#000000"/>
        <bottomPen lineWidth="0.5" lineColor="#000000"/>
        <rightPen lineWidth="0.5" lineColor="#000000"/>
    </box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
    <box>
        <pen lineWidth="0.5" lineColor="#000000"/>
        <topPen lineWidth="0.5" lineColor="#000000"/>
        <leftPen lineWidth="0.5" lineColor="#000000"/>
        <bottomPen lineWidth="0.5" lineColor="#000000"/>
        <rightPen lineWidth="0.5" lineColor="#000000"/>
    </box>
</style>
<style name="DataStyle" hTextAlign="Center" isBlankWhenNull="true" fontName="Arial" fontSize="8" isBold="false"/>
<subDataset name="WaterLevelForecastDataSet" uuid="01de13e9-d88f-4fef-b1bf-4de28bf02e6a">
    <parameter name="waterlevelForecastData" class="com.example.reporting.WaterlevelForecastReportService.WaterlevelForecastData">
        <parameterDescription><![CDATA[]]></parameterDescription>
    </parameter>
    <field name="waterLevel" class="com.example.WaterLevelForecast">
        <fieldDescription><![CDATA[_THIS]]></fieldDescription>
    </field>
</subDataset>
<parameter name="logo" class="Object" isForPrompting="false">
    <defaultValueExpression><![CDATA[]]></defaultValueExpression>
</parameter>
<queryString>
    <![CDATA[]]>
</queryString>
<field name="waterlevelForecastData" class="com.example.reporting.WaterlevelForecastReportService.WaterlevelForecastData">
    <fieldDescription><![CDATA[_THIS]]></fieldDescription>
</field>
<detail>
    <band height="200">
        <frame>
            <reportElement x="0" y="0" width="100" height="42" uuid="a532b32e-a9e0-427b-84c4-d60fe9589d84">
                <property name="local_mesure_unitx" value="pixel"/>
                <property name="com.jaspersoft.studio.unit.x" value="px"/>
                <property name="local_mesure_unitwidth" value="pixel"/>
                <property name="com.jaspersoft.studio.unit.width" value="px"/>
                <property name="local_mesure_unitheight" value="pixel"/>
                <property name="com.jaspersoft.studio.unit.height" value="px"/>
                <property name="local_mesure_unity" value="pixel"/>
                <property name="com.jaspersoft.studio.unit.y" value="px"/>
            </reportElement>
            <componentElement>
                <reportElement x="0" y="0" width="100" height="42" isRemoveLineWhenBlank="true" uuid="f4166ea1-a21d-4ed8-8f16-02ae243c81f1">
                    <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
                    <property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
                    <property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
                    <property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
                    <property name="net.sf.jasperreports.export.headertoolbar.table.name" value=""/>
                    <property name="com.jaspersoft.studio.unit.x" value="pixel"/>
                </reportElement>
                <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                    <datasetRun subDataset="WaterLevelForecastDataSet" uuid="15b7c136-4802-4b6b-bd8c-cbde01ec9bed">
                        <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{waterlevelForecastData}.getWaterlevelForecastList())]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="100" uuid="d70db54d-dd19-40c3-a36c-1d9592008fcc">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
                        <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                        <jr:columnHeader style="Table_CH" height="30" rowSpan="1">
                            <property name="com.jaspersoft.studio.unit.width" value="px"/>
                            <staticText>
                                <reportElement style="Table_CH" x="0" y="0" width="100" height="30" uuid="7fa06c16-b4cc-450e-a204-6fe97e18c1a4">
                                    <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                                </reportElement>
                                <text><![CDATA[Datum]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell style="Table_TD" height="12">
                            <property name="com.jaspersoft.studio.unit.height" value="px"/>
                            <textField isStretchWithOverflow="true">
                                <reportElement style="DataStyle" x="0" y="0" width="100" height="12" uuid="75c92bc7-279f-4ea5-95dd-2005b43669f2">
                                    <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                                </reportElement>
                                <box>
                                    <topPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                                    <leftPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                                    <bottomPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                                    <rightPen lineWidth="0.0" lineStyle="Solid" lineColor="#000000"/>
                                </box>
                                <textFieldExpression><![CDATA[new java.text.SimpleDateFormat("E dd.MM.yyyy", $P{REPORT_LOCALE}).format($F{waterLevel}.getTime())]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>
        </frame>
        <frame>
            <reportElement positionType="Float" x="570" y="0" width="230" height="200" uuid="386949ed-e289-4e9d-82af-54f7a1afbb6e"/>
            <box>
                <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
                <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
            </box>
            <staticText>
                <reportElement style="DataStyle" x="11" y="11" width="59" height="12" uuid="a63c6262-34f9-4731-9ad4-22bf6a2a54d2"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[Pegelort:]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="11" y="31" width="59" height="12" uuid="d56daa72-b14f-442b-8868-4bba5601f47f"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[Position:]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="11" y="51" width="58" height="12" uuid="056f6c4b-375e-4d88-8aa4-900da296b655"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[MHW (mPN):]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="11" y="71" width="57" height="12" uuid="30d9f8de-2612-4c2a-b319-39b01f6d2809"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[MNW (mPN):]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="11" y="91" width="57" height="12" uuid="51b3bc61-c9f3-4b48-9f72-df980ea80c2e"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[PN (mNN):]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="11" y="111" width="218" height="12" uuid="ddaea131-e7f8-4215-bada-f489b37896a9"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[Der Wasserstand bezieht sich auf Pegelnull.]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="11" y="123" width="29" height="12" uuid="54323c5e-1213-441f-9bda-41b6415d9158"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[HW]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="11" y="135" width="29" height="12" uuid="9974d608-8a33-4f35-ae72-07388f9ae138"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[NW]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="11" y="147" width="29" height="12" uuid="428c7ee2-46c1-4008-b355-8ac357c51057"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[MHW]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="11" y="159" width="29" height="12" uuid="81b95147-96f0-4227-b9a9-cf51c5db0c8c"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[MNW]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="11" y="183" width="29" height="12" uuid="38ef4fc2-05dd-4aae-8510-c50002d2492e"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[NN]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="11" y="171" width="29" height="12" uuid="8c9e77a4-65ea-4ef4-b8e4-b4b3620c3f0e"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[PN]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="40" y="123" width="160" height="12" uuid="66fd279e-95db-4970-b70f-aaa298929472"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[= Hochwasser]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="40" y="135" width="160" height="12" uuid="03b13ac8-169c-419c-a407-749b41c55f4a"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[= Niedrigwasser]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="40" y="147" width="160" height="12" uuid="f5bc3c27-f772-44d7-8679-f69a52d0f3e8"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[= Mittleres Hochwasser]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="40" y="159" width="160" height="12" uuid="8124681f-f321-4cde-986b-458318ef925f"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[= Mittleres Niedrigwasser]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="40" y="171" width="160" height="12" uuid="8bd1a23e-b9a6-48c9-afc3-8d01a901327a"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[= Pegelnull]]></text>
            </staticText>
            <staticText>
                <reportElement style="DataStyle" x="40" y="183" width="160" height="12" uuid="96bb6dce-c1cd-490b-93f5-5aca18234fe2"/>
                <textElement textAlignment="Left"/>
                <text><![CDATA[= Normalnull]]></text>
            </staticText>
        </frame>
    </band>
</detail>
<pageFooter>
    <band height="30">
        <textField isStretchWithOverflow="true">
            <reportElement positionType="Float" x="0" y="10" width="800" height="20" uuid="0d80af3a-fdab-42df-a876-9debf03164e8">
                <property name="local_mesure_unitx" value="pixel"/>
                <property name="local_mesure_unity" value="pixel"/>
                <property name="local_mesure_unitwidth" value="pixel"/>
                <property name="com.jaspersoft.studio.unit.width" value="px"/>
                <property name="local_mesure_unitheight" value="pixel"/>
                <property name="com.jaspersoft.studio.unit.height" value="px"/>
            </reportElement>
            <textElement>
                <font fontName="Arial" size="7"/>
            </textElement>
            <textFieldExpression><![CDATA[$R{label.hvcc.disclaimer}]]></textFieldExpression>
        </textField>
    </band>
</pageFooter>

如果我从此报告模板生成PDF文件,我总是在末尾收到一个空白页面,其中只包含页脚,没有内容。

根据我的理解,这是因为左边的表格和细节带1的底部之间的空间,将在生成报告时添加到表格的末尾。因此,如果下表和下面的空格对于一个页面来说很大,则会向PDF中添加一个仅包含空格和页脚的附加页面。

如果我移除右侧的框架并将细节带1的高度降低到表的末尾,一切都很好,不会添加额外的页面。但是我需要在报告模板中使用此空间,因为右侧的框架包含静态文本。

如何更改报告模板以减少细节带1的高度,以便表格下方的空间不会添加到PDF中,但对右侧框架的定义没有影响?

我通过更改拉伸和溢出选项尝试了很多次,但我最后总是得到一个空白页。

解决方法

如果我在右侧使用子报表,并将子报表元素的高度设置为左侧表格的相同高度,则详细信息带1的高度可以减少到表格的末尾,在生成的报告中,表格后面不会添加任何空格,也不会呈现额外的页面。 但我认为有可能在不使用子报告的情况下实现这一目标。

0 个答案:

没有答案