JasperReports 在 PDF 末尾包含空白页

发布于 2024-12-26 01:45:13 字数 10770 浏览 4 评论 0原文

我正在使用 Java 中的 JasperReports 生成 PDF。我终于成功地让 Jasper 正确地对报告进行了分页。问题是,现在我在报告末尾看到一个空白页(标题已打印,但详细信息区域为空白)。详细信息带传递的信息已全部显示,因此不需要该页面(而且最后一页的末尾有一个空白区域)。我将在问题末尾附上 JXML,如有帮助,我们将不胜感激。

谢谢!

这是 JXML 文件的内容:

 <?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="tintoreria" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isFloatColumnFooter="true">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="288"/>
    <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA["C:\\work\\REPO-CTK\\lasastra-world\\core\\src\\main\\resources\\jasper\\tintoreria\\"]]></defaultValueExpression>
    </parameter>
    <parameter name="totalItems" class="java.lang.String"/>
    <parameter name="nroPag" class="java.lang.String"/>
    <parameter name="totalPag" class="java.lang.String"/>
    <parameter name="supplier" class="java.lang.String"/>
    <parameter name="creationDate" class="java.lang.String"/>
    <parameter name="orderNumber" class="java.lang.String"/>
    <parameter name="fechaPedido" class="java.lang.String"/>
    <parameter name="datasourceParam" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <pageHeader>
        <band height="119" splitType="Stretch">
            <rectangle radius="10">
                <reportElement x="0" y="0" width="555" height="119" backcolor="#CCCCFF"/>
                <graphicElement>
                    <pen lineWidth="1.75"/>
                </graphicElement>
            </rectangle>
            <staticText>
                <reportElement x="112" y="7" width="241" height="32"/>
                <textElement>
                    <font size="24" isBold="true" isUnderline="true"/>
                </textElement>
                <text><![CDATA[Orden de compra]]></text>
            </staticText>
            <staticText>
                <reportElement x="286" y="62" width="63" height="20"/>
                <textElement>
                    <font size="12"/>
                </textElement>
                <text><![CDATA[Proveedor:]]></text>
            </staticText>
            <textField>
                <reportElement x="355" y="62" width="189" height="20"/>
                <textElement>
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{supplier}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="281" y="42" width="72" height="20"/>
                <textElement>
                    <font size="12"/>
                </textElement>
                <text><![CDATA[Orden Nro:]]></text>
            </staticText>
            <textField>
                <reportElement x="355" y="42" width="189" height="20"/>
                <textElement>
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{orderNumber}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="268" y="83" width="85" height="20"/>
                <textElement>
                    <font size="12"/>
                </textElement>
                <text><![CDATA[Fecha Pedido:]]></text>
            </staticText>
            <textField>
                <reportElement x="355" y="83" width="189" height="20"/>
                <textElement>
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{creationDate}]]></textFieldExpression>
            </textField>
        </band>
    </pageHeader>
    <detail>
        <band height="633" splitType="Stretch">
            <subreport runToBottom="false">
                <reportElement positionType="Float" stretchType="RelativeToBandHeight" mode="Transparent" x="0" y="0" width="555" height="633" isRemoveLineWhenBlank="true" isPrintInFirstWholeBand="true"/>
                <dataSourceExpression><![CDATA[$P{datasourceParam}]]></dataSourceExpression>
                <subreportExpression><![CDATA["purchaseorder_subreport1.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
    <pageFooter>
        <band height="50" splitType="Stretch">
            <rectangle radius="10">
                <reportElement positionType="Float" x="0" y="0" width="555" height="50" backcolor="#CCCCFF"/>
                <graphicElement>
                    <pen lineWidth="1.75"/>
                </graphicElement>
            </rectangle>
            <textField>
                <reportElement positionType="Float" x="22" y="15" width="239" height="20"/>
                <textElement>
                    <font size="13"/>
                </textElement>
                <textFieldExpression><![CDATA["Cantidad de items: " + $P{totalItems}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="331" y="25" width="159" height="20"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression><![CDATA["Pagina  "+$V{PAGE_NUMBER}+" de "]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report">
                <reportElement x="490" y="25" width="40" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
        </band>
    </pageFooter>
</jasperReport>

这是子报表:

<?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="tintoreria_subreport1" pageWidth="540" pageHeight="600" whenNoDataType="NoDataSection" columnWidth="540" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isFloatColumnFooter="true" whenResourceMissingType="Empty">
    <property name="ireport.zoom" value="1.5394743546921208"/>
    <property name="ireport.x" value="131"/>
    <property name="ireport.y" value="0"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="itemNumber" class="java.lang.String"/>
    <field name="description" class="java.lang.String"/>
    <field name="amount" class="java.lang.String"/>
    <columnHeader>
        <band height="22" splitType="Stretch">
            <staticText>
                <reportElement x="1" y="1" width="68" height="20"/>
                <textElement>
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Item]]></text>
            </staticText>
            <staticText>
                <reportElement x="76" y="1" width="373" height="20"/>
                <textElement>
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[   Descripción]]></text>
            </staticText>
            <line>
                <reportElement x="69" y="1" width="1" height="21"/>
            </line>
            <line>
                <reportElement x="0" y="21" width="540" height="1"/>
            </line>
            <line>
                <reportElement x="448" y="0" width="1" height="21"/>
            </line>
            <staticText>
                <reportElement x="453" y="1" width="68" height="20"/>
                <textElement>
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Cantidad]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="13" splitType="Stretch">
            <textField>
                <reportElement x="1" y="0" width="68" height="12"/>
                <textElement>
                    <font size="9"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{itemNumber}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="77" y="0" width="371" height="12"/>
                <textElement>
                    <font size="9"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{description}]]></textFieldExpression>
            </textField>
            <line>
                <reportElement x="69" y="0" width="1" height="13"/>
            </line>
            <line>
                <reportElement x="448" y="0" width="1" height="13"/>
            </line>
            <textField>
                <reportElement x="453" y="1" width="75" height="12"/>
                <textElement>
                    <font size="9"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{amount}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

I'm generating a PDF using JasperReports from Java. I finally succeeded in making Jasper correctly paginate the report. The problem is that now I'm getting a blank page at the end of the report (the headers are printed, but the detail band is blank). The information passed for the detail band is all displayed, so there is no need for that page (what is more, there is an empty space at the end of the last page). I will attach the JXML at the end of the question, any help appreciated.

Thanks!

This is the content of the JXML file:

 <?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="tintoreria" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" isFloatColumnFooter="true">
    <property name="ireport.zoom" value="1.0"/>
    <property name="ireport.x" value="0"/>
    <property name="ireport.y" value="288"/>
    <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA["C:\\work\\REPO-CTK\\lasastra-world\\core\\src\\main\\resources\\jasper\\tintoreria\\"]]></defaultValueExpression>
    </parameter>
    <parameter name="totalItems" class="java.lang.String"/>
    <parameter name="nroPag" class="java.lang.String"/>
    <parameter name="totalPag" class="java.lang.String"/>
    <parameter name="supplier" class="java.lang.String"/>
    <parameter name="creationDate" class="java.lang.String"/>
    <parameter name="orderNumber" class="java.lang.String"/>
    <parameter name="fechaPedido" class="java.lang.String"/>
    <parameter name="datasourceParam" class="net.sf.jasperreports.engine.data.JRBeanCollectionDataSource"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <pageHeader>
        <band height="119" splitType="Stretch">
            <rectangle radius="10">
                <reportElement x="0" y="0" width="555" height="119" backcolor="#CCCCFF"/>
                <graphicElement>
                    <pen lineWidth="1.75"/>
                </graphicElement>
            </rectangle>
            <staticText>
                <reportElement x="112" y="7" width="241" height="32"/>
                <textElement>
                    <font size="24" isBold="true" isUnderline="true"/>
                </textElement>
                <text><![CDATA[Orden de compra]]></text>
            </staticText>
            <staticText>
                <reportElement x="286" y="62" width="63" height="20"/>
                <textElement>
                    <font size="12"/>
                </textElement>
                <text><![CDATA[Proveedor:]]></text>
            </staticText>
            <textField>
                <reportElement x="355" y="62" width="189" height="20"/>
                <textElement>
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{supplier}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="281" y="42" width="72" height="20"/>
                <textElement>
                    <font size="12"/>
                </textElement>
                <text><![CDATA[Orden Nro:]]></text>
            </staticText>
            <textField>
                <reportElement x="355" y="42" width="189" height="20"/>
                <textElement>
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{orderNumber}]]></textFieldExpression>
            </textField>
            <staticText>
                <reportElement x="268" y="83" width="85" height="20"/>
                <textElement>
                    <font size="12"/>
                </textElement>
                <text><![CDATA[Fecha Pedido:]]></text>
            </staticText>
            <textField>
                <reportElement x="355" y="83" width="189" height="20"/>
                <textElement>
                    <font size="12"/>
                </textElement>
                <textFieldExpression><![CDATA[$P{creationDate}]]></textFieldExpression>
            </textField>
        </band>
    </pageHeader>
    <detail>
        <band height="633" splitType="Stretch">
            <subreport runToBottom="false">
                <reportElement positionType="Float" stretchType="RelativeToBandHeight" mode="Transparent" x="0" y="0" width="555" height="633" isRemoveLineWhenBlank="true" isPrintInFirstWholeBand="true"/>
                <dataSourceExpression><![CDATA[$P{datasourceParam}]]></dataSourceExpression>
                <subreportExpression><![CDATA["purchaseorder_subreport1.jasper"]]></subreportExpression>
            </subreport>
        </band>
    </detail>
    <pageFooter>
        <band height="50" splitType="Stretch">
            <rectangle radius="10">
                <reportElement positionType="Float" x="0" y="0" width="555" height="50" backcolor="#CCCCFF"/>
                <graphicElement>
                    <pen lineWidth="1.75"/>
                </graphicElement>
            </rectangle>
            <textField>
                <reportElement positionType="Float" x="22" y="15" width="239" height="20"/>
                <textElement>
                    <font size="13"/>
                </textElement>
                <textFieldExpression><![CDATA["Cantidad de items: " + $P{totalItems}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="331" y="25" width="159" height="20"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression><![CDATA["Pagina  "+$V{PAGE_NUMBER}+" de "]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report">
                <reportElement x="490" y="25" width="40" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
        </band>
    </pageFooter>
</jasperReport>

And this is the subreport:

<?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="tintoreria_subreport1" pageWidth="540" pageHeight="600" whenNoDataType="NoDataSection" columnWidth="540" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isFloatColumnFooter="true" whenResourceMissingType="Empty">
    <property name="ireport.zoom" value="1.5394743546921208"/>
    <property name="ireport.x" value="131"/>
    <property name="ireport.y" value="0"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="itemNumber" class="java.lang.String"/>
    <field name="description" class="java.lang.String"/>
    <field name="amount" class="java.lang.String"/>
    <columnHeader>
        <band height="22" splitType="Stretch">
            <staticText>
                <reportElement x="1" y="1" width="68" height="20"/>
                <textElement>
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Item]]></text>
            </staticText>
            <staticText>
                <reportElement x="76" y="1" width="373" height="20"/>
                <textElement>
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[   Descripción]]></text>
            </staticText>
            <line>
                <reportElement x="69" y="1" width="1" height="21"/>
            </line>
            <line>
                <reportElement x="0" y="21" width="540" height="1"/>
            </line>
            <line>
                <reportElement x="448" y="0" width="1" height="21"/>
            </line>
            <staticText>
                <reportElement x="453" y="1" width="68" height="20"/>
                <textElement>
                    <font size="12" isBold="true"/>
                </textElement>
                <text><![CDATA[Cantidad]]></text>
            </staticText>
        </band>
    </columnHeader>
    <detail>
        <band height="13" splitType="Stretch">
            <textField>
                <reportElement x="1" y="0" width="68" height="12"/>
                <textElement>
                    <font size="9"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{itemNumber}]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement x="77" y="0" width="371" height="12"/>
                <textElement>
                    <font size="9"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{description}]]></textFieldExpression>
            </textField>
            <line>
                <reportElement x="69" y="0" width="1" height="13"/>
            </line>
            <line>
                <reportElement x="448" y="0" width="1" height="13"/>
            </line>
            <textField>
                <reportElement x="453" y="1" width="75" height="12"/>
                <textElement>
                    <font size="9"/>
                </textElement>
                <textFieldExpression><![CDATA[$F{amount}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
</jasperReport>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

峩卟喜欢 2025-01-02 01:45:13

您应该手动隐藏 Detail 之后的区域。
例如,尝试通过将 Print When Expression 设置为 Boolean.FALSE 来隐藏 Summary 带区。

<summary>
     <band height="1" splitType="Stretch">
           <printWhenExpression><![CDATA[Boolean.FALSE]]></printWhenExpression>
     </band>
</summary>

注意:不确定确切的 XML 上下文,因为我通常在 iReport 中进行。

You should manually hide the bands after Detail.
For example try hiding the Summary band by setting it's Print When Expression to Boolean.FALSE

<summary>
     <band height="1" splitType="Stretch">
           <printWhenExpression><![CDATA[Boolean.FALSE]]></printWhenExpression>
     </band>
</summary>

Note: not sure about the exact XML context, since I usually do it in iReport.

少钕鈤記 2025-01-02 01:45:13

我遇到了这个问题,就我而言,解决方法是:

  1. 转到报告属性。
  2. 然后选中忽略分页属性。

就是这样。我希望它有帮助。

I faced this issue, in my case it is solved by:

  1. Go to Report Properties.
  2. Then check Ignore Pagination property.

That's it. I hope it helps.

爱的那么颓废 2025-01-02 01:45:13

这个问题可能是由于报告中的空白区域造成的,在 jasper 中,有一个设置,如果您右键单击一个带区,它会显示“拉伸到内容”,请单击它

This issue may be due to empty space in report, In jasper there is a setting if you right click a band it says "Strectch to contents",click it

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文