如果超过一页,如何在除最后一页之外的所有页面上包含“姓名缩写”行?

时间:2013-10-07 20:04:12

标签: jasper-reports

iReport 中,我需要在除最后一页之外的文档中的所有页脚上打印一些文本,但仅当在一个页面中存在多个页面时文档。

用例是我需要人们初始化文档的每个页面,然后在最后签名。事情可能适合一页,但可能是50页。我需要第1..49页的初始行,然后是第50页的签名行。

起初,我认为我只需要直接 PrintWhenExpression 就可以做到这一点:

 new Boolean($V{PAGE_NUMBER} == 1 && $V{PAGE_COUNT} > 1)

但是,根据它们的评估时间(现在,与报告与页面对比),这似乎并未正确评估。

2 个答案:

答案 0 :(得分:2)

这篇文章描述了很好的解决方案:Compare current page number with last page number。我在下面的示例中使用过它。


简短说明

借助摘要页面,我们可以设置最后一页已经绘制的标志
要初始化此标记,我们可以使用摘要频段的 printWhenExpression

样本

jrxml 文件:

<?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="last_page_on_page_footer" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="37b03978-a847-40ab-bd19-40bd48de326d">
    <queryString>
        <![CDATA[SELECT TASK FROM TASKS]]>
    </queryString>
    <field name="TASK" class="java.lang.String"/>
    <detail>
        <band height="50" splitType="Stretch">
            <textField>
                <reportElement uuid="bec3ccda-ea30-49fa-a0ad-5bb74a2187a5" x="0" y="0" width="100" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[$F{TASK}]]></textFieldExpression>
            </textField>
        </band>
    </detail>
    <pageFooter>
        <band height="54" splitType="Stretch">
            <textField evaluationTime="Report">
                <reportElement uuid="5e4bb895-fd64-4627-bd35-ca1ed71f8dc1" x="455" y="0" width="100" height="20">
                    <printWhenExpression><![CDATA[!$P{REPORT_PARAMETERS_MAP}.containsKey("LastPageNumber")]]></printWhenExpression>
                </reportElement>
                <textElement/>
                <textFieldExpression><![CDATA["initials: ___________"]]></textFieldExpression>
            </textField>
            <textField>
                <reportElement uuid="788fbc43-92cc-4540-abeb-8fa9bf48d25c" x="0" y="0" width="80" height="20"/>
                <textElement textAlignment="Right"/>
                <textFieldExpression><![CDATA["Page "+$V{PAGE_NUMBER}+" of"]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report">
                <reportElement uuid="95286826-b864-46f8-9922-fc0e2f023ba5" x="80" y="0" width="40" height="20"/>
                <textElement/>
                <textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
            </textField>
            <textField evaluationTime="Report">
                <reportElement uuid="25ccab25-ccd2-4187-8a9b-dff54276042e" x="455" y="0" width="100" height="20">
                    <printWhenExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}.containsKey("LastPageNumber")]]></printWhenExpression>
                </reportElement>
                <textElement/>
                <textFieldExpression><![CDATA["Signature: ___   "]]></textFieldExpression>
            </textField>
        </band>
    </pageFooter>
    <summary>
        <band height="20">
            <printWhenExpression><![CDATA[new Boolean(($P{REPORT_PARAMETERS_MAP}.put(
"LastPageNumber",$V{PAGE_NUMBER}).equals("dummyPrintWhen")) ||
Boolean.TRUE)]]></printWhenExpression>
        </band>
    </summary>
</jasperReport>

报告的设计(在 iReport 中):

enter image description here

结果将是。第一页(1/2):

enter image description here

第二页(最后一页):

enter image description here

如果只有一页,结果将是:

enter image description here

在我的示例中,我将一个 textField 放在另一个后面。

答案 1 :(得分:0)

只需添加乐队“最后一页页脚”即可 这样,您可以为所有页​​面设置一个页脚,但最后一页和最后一页的单独页脚。

相关问题