首页 > 解决方案 > How to hide/show and image or textField on last page?

问题描述

In Jasper studio how can I disable/show background for a single page in the report.

I want to disable the watermark image which I set in the background for the last page.

标签: jasper-reports

解决方案


当您需要将当前页面与总页数进行比较时,我知道的最简单的方法是在元素上使用评估类型“自动”。

评估时间枚举

变量将在对应于其重置类型的时间进行评估。

解决方案改编自 lucianc 在https://community.jaspersoft.com/questions/514622/print-when-last-page的回答

创建一个包含具有重置类型 Page 的当前页面的变量(因此它在 Auto 作为当前页码时进行评估)

 <variable name="currentPageInAutoEval" class="java.lang.Integer" resetType="Page">
    <variableExpression>$V{PAGE_NUMBER}</variableExpression>
 </variable

在您的元素(文本字段、图像等)上将评估时间设置为“自动”,并在表达式中使用三元运算符

在您的情况下,最后一页上没有图像

<image evaluationTime="Auto">
    <imageExpression>$V{currentPageInAutoEval}.equals($V{PAGE_NUMBER}) ? null : yourImage</imageExpression>
</image>

因此 withevalutationTime="Auto" $V{currentPageInAutoEval}将被评估为当前页码的 resetType (Page) 和$V{PAGE_NUMBER}总页数。


推荐阅读