【问题标题】:JasperReports including blank page at the end of the PDFJasperReports 包括 PDF 末尾的空白页
【发布时间】:2020-07-08 15:04:24
【问题描述】:

我正在使用 Java 中的 JasperReports 生成 PDF。我终于成功地让 Jasper 正确地对报告进行了分页。问题是现在我在报告末尾得到一个空白页(打印了标题,但详细信息带是空白的)。为detail band传递的信息全部显示,所以不需要那个页面(更何况,最后一页的末尾有一个空格)。我将在问题末尾附上 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>

【问题讨论】:

  • 你曾经解决过这个问题吗?

标签: java jasper-reports ireport


【解决方案1】:

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

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

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

【讨论】:

  • 感谢您的回复。我已经从 iReport 的文档中删除了所有带区,只留下了页眉、详细信息和页脚。在子报表中只有列标题和详细信息,所以我认为这不能解决问题,但我会尝试。
  • 这确实解决了我的问题,即我的一些报告(和子报告)中出现了多余的页面。
  • 这解决了问题,但如果数据存在,它也不会显示页面。如何检查数据是否存在?
【解决方案2】:

我遇到了这个问题,就我而言,它是通过以下方式解决的:

  1. 转到报告属性。
  2. 然后检查 Ignore Pagination 属性。

就是这样。希望对你有帮助。

【讨论】:

  • 也为我工作,在我的情况下,我只有标题带和一个列表,由于某种原因打印了一个额外的页面
  • 虽然这种方法解决了额外空白页面的问题,但我注意到了一个缺点:如果内容的高度超过指定的页面高度,页面就会变得更长。如果报告打算在标准纸张(A4、Letter 等)上打印,这可能是个问题
  • 当报告打算打印在连续纸上时应该使用它。这不是一个适当的解决方案。
【解决方案3】:

这个问题可能是由于报告中的空白,在jasper中有一个设置,如果你右键单击一个显示“拉伸到内容”的乐队,点击它

【讨论】:

    猜你喜欢
    • 2018-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-31
    • 1970-01-01
    • 2017-06-20
    • 1970-01-01
    相关资源
    最近更新 更多