如何包含“姓名缩写”当超过一页时,除了最后一页以外的所有页面上的行? [英] How to include "initials" line on all pages except last page when more then one page?

查看:144
本文介绍了如何包含“姓名缩写”当超过一页时,除了最后一页以外的所有页面上的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In iReport I am needing to print some text on all the page footers in a document except the last page, but only when there exists more than one page in a document.

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

The use case is I need people to initial each page of the document and then sign at the end. Things may fit on one page, but it may be 50 pages. I need initial lines on pages 1..49 and then the signature line on page 50.

起初我认为我可以用直接 PrintWhenExpression

At first I'd think I could do this with just a straight PrintWhenExpression:

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

但是看起来这些根本不会被正确评估评估(现在,与报告与页面对比)。

But that does not it appears that those are not evaluated correctly depending on when they are evaluated (now, vs. report vs. page).

推荐答案

这篇文章描述了一个很好的解决方案:将当前页码与最后一页的页码进行比较。我在下面的示例中使用过它。

The nice solution was described in this post: Compare current page number with last page number. I've used it in the sample below.

借助摘要页面,我们可以设置最后一页已经绘制的标志

用于初始化此标志我们可以使用摘要频段的 printWhenExpression

With help of Summary page we can set the flag that the last page was already drawn.
For initializing this flag we can use the printWhenExpression of the Summary band.

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 中):

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

The result will be. First page (1 of 2):

第二个(最后一页):

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

In case only one page the result will be:

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

In my sample I've placed one textField behind the other one.

这篇关于如何包含“姓名缩写”当超过一页时,除了最后一页以外的所有页面上的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆