print when for last page

How do I get a print when for the last page?


This works fine for the first page, but PAGE_NUMBER is not evaluated for both page and report at the same time.

new Boolean($V{PAGE_NUMBER}.intValue()==1)

I need something like:

new Boolean($V{PAGE_NUMBER}.intValue()==$V{PAGES_IN_REPORT})
jwindberg's picture
1602
Joined: Nov 9 2006 - 1:29am
Last seen: 16 years 10 months ago

18 Answers:

Just in case anyone wants to know why I need this.

Automatic paper folders that take printed items and fold them into envelopes specify that there are bars printed on the right edge of the form, about midway down.
I was hoping to place them on the background band.
If the report is one page, then there are two bars. If it is more than one page, there is one bar per page until the last page, where there are two bars.

Thus I had planned on putting on bar on the report in the background, and a second bar below it, and tagging it with a print when that was "print on last page".

So, I really need print on last page..

Help!!!!!
jwindberg's picture
1602
Joined: Nov 9 2006 - 1:29am
Last seen: 16 years 10 months ago
You can achieve this using the "Auto" evaluation type.

You basically need to compare the current page number against the total page number, which is only known when the report generation completes. Since the "Auto" evaluation type decides when to evaluate a variable based on its reset type, you will need to copy the PAGE_NUMBER value into a variable that has "Page" reset type. This variable will be evaluated as the current page number, while PAGE_NUMBER will be evaluated to the total page number.

You will have something like
Code:
<br />
<variable name="currentPage" class="java.lang.Integer" resetType="Page"><br />
	<variableExpression>$V{PAGE_NUMBER}</variableExpression><br />
</variable><br />
..<br />
<background><br />
	..<br />
	<image evaluationTime="Auto"><br />
<imageExpression>$V{currentPage}.equals($V{PAGE_NUMBER}) ? your_image : null</imageExpression><br />
	</image><br />
	..<br />
</background><br />
</td></tr></tbody></table><br />
<br />
HTH,<br />
Lucian
lucianc's picture
86899
Joined: Jul 17 2006 - 1:10am
Last seen: 5 hours 29 min ago
I had a similar problem where I had to print something on the last page only.

Do an evaluation checking if the current page number variable is equal to the total page count. Make sure the evaluation time is at Report time. That'll make it so that the variable is taken at the end.

Plus doing some tests with the evaluation times will help you a lot! And using those Summary and Last Page Footer bands as well. Like the summary band will always be at the end so thats good for something.
DMA02's picture
296
Joined: Dec 7 2006 - 6:26pm
Last seen: 16 years 9 months ago
There's the trick.
There does not seem to be a way to know the current page and the total page count at the same time.
There is one variable, PAGE_NUMBER, which is evaluated either at "NOW" or at "REPORT", but you can't know both at the same time.
jwindberg's picture
1602
Joined: Nov 9 2006 - 1:29am
Last seen: 16 years 10 months ago
That looks close to what I need, but I failed to explain that I was trying to do this with a line.
How do I specify evaluationTime="Auto" on a line?



<variable name="CURRENT_PAGE" class="java.lang.Integer" resetType="Page" calculation="Nothing"> <variableExpression><![CDATA[$V{PAGE_NUMBER}]]></variableExpression>
</variable>

<line direction="TopDown">
<reportElement x="565" y="390" width="29" height="0" key="line-14"> <printWhenExpression>
<![CDATA[new Boolean($V{CURRENT_PAGE}.equals($V{PAGE_NUMBER}))]]>
</printWhenExpression>
</reportElement>
<graphicElement stretchType="NoStretch" pen="2Point"/>
</line>
jwindberg's picture
1602
Joined: Nov 9 2006 - 1:29am
Last seen: 16 years 10 months ago
For that matter...
What the heck does evaulationTime="Auto" mean?

It's not in my book, "Jasper Reports for Java Developers".

It seems to be capable of comparing now to then, but how does it know what I intend.

It works, that's cool, but such black magic scares me so.
jwindberg's picture
1602
Joined: Nov 9 2006 - 1:29am
Last seen: 16 years 10 months ago
You can find [url=http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/JRE... a brief description of the "Auto" evaluation feature.

Regarding the implementation, it's not exactly magic: the values of the expression participants (fields, variables) are kept in the report element until all the values are available, and at that moment the expression gets evaluated using the saved values.

This is only applicable to expressions that can have delayed evaluation, and unfortunately the report element "print when" expressions are not among these. Therefore you will not be able to use "Auto" evaluation to decide whether to print a line or not.

Still, the image source expression can have delayed evaluation and you can use an image to "simulate" a line that only prints on the last page.

Regards,
Lucian
lucianc's picture
86899
Joined: Jul 17 2006 - 1:10am
Last seen: 5 hours 29 min ago
The mere placement of
<variable name="CURRENT_PAGE" class="java.lang.Integer" resetType="Page" calculation="Nothing">
<variableExpression>$V{PAGE_NUMBER}</variableExpression>
</variable>

in my template causes things in the header, footer, and intro to vanish.

I take it out, and the report works again.
jwindberg's picture
1602
Joined: Nov 9 2006 - 1:29am
Last seen: 16 years 10 months ago
damn damn damn damn

on a report where the last page only gets a summary, this trick fails.
If I use the lastPageFooter, that fails as well.
The lastPageFooter prints on the second to the last page, while the summary prints on the last page.
The mark I'm trying to put on the last page is for an automatic folder. The mark MUST be on the last page, and it must be in the same postition on the page as it is everywhere else on the report.
jwindberg's picture
1602
Joined: Nov 9 2006 - 1:29am
Last seen: 16 years 10 months ago
Hi,

The summary sections is special because it does not get accompanied by the page header or footer (some people want it to behave like this).
What you need is to simulate the summary sections as explained here:
http://jasperforge.org/sf/wiki/do/viewPage/projects.jasperreports/wiki/F...

If you do so, the lastPageFooter would really be on the last page and you could even place elements at a negative Y on that last page footer so that they appear higher on the page.

I hope this helps.
Teodor
teodord's picture
53238
Joined: Jun 30 2006 - 9:00am
Last seen: 2 hours 29 min ago
what section would you use for totals at the end of the detail area if not summary?
jwindberg's picture
1602
Joined: Nov 9 2006 - 1:29am
Last seen: 16 years 10 months ago

Hello... I am having similar issues.  I am trying to print something in the Page Footer only on the last page.  I have three fields in the last page... two text fields and the page number.  I'd like the two text fields to only print on the last page.

I've tried a variety of things with no luck... setting the current page and last page... then printing when they equal.  Also, setting a isLastPage boolean and checking that... so far no luck.

Can anyone please help and/or is there an example somewhere?

bwestendorf's picture
Joined: Feb 26 2009 - 4:19pm
Last seen: 14 years 7 months ago

Brian,

 

If you have the same problem, you must use the same solution.

We've already mentioned the lastPageFooter section. Did you use it?

 

Also, I have indicated that the footer section of a dummy group that has no group expression could be used as summary, in case the true <summary> section does not work as expected (but John ignored my solution and asked again what section he should use).

 

I hope this helps.

Teodor

 

teodord's picture
53238
Joined: Jun 30 2006 - 9:00am
Last seen: 2 hours 29 min ago

Hi,

I have a chart in the summary band, how can i solve the same problem of page footer?

i have tried it with the last page footes, but it didnt work.

i hope someone can help me

thanks

 

nnvc's picture
527
Joined: Jul 31 2009 - 9:57am
Last seen: 14 years 1 month ago

Hi,

I am not able to use that link to the FAQ's. I also tried that method to put the elements to last page footer section and put a negative y for a different position, but they won't get printed. Urgent, need help.

yukini's picture
181
Joined: Nov 24 2009 - 11:29pm
Last seen: 13 years 10 months ago

Hi,

 

Please do not post more replies to this thread. The original thread is from 2006 and many things have happened since.

The FAQs were moved here:

http://jasperforge.org/website/jasperreportswebsite/trunk/faq.html

 

New features were added to the engine, including the isSummaryWithPageHeaderAndFooter option.

 

Please create a new thread for your problem and try explain it the best you can, providing screenshot and sample files if possible.

 

Thank you,

Teodor

 

teodord's picture
53238
Joined: Jun 30 2006 - 9:00am
Last seen: 2 hours 29 min ago
I use a similar solution but for show a variable in the last page. In addition check "Blank when null" for the text field.

Regards.
German
gbisogno's picture
155
Joined: Feb 23 2007 - 7:45am
Last seen: 16 years 7 months ago

Have a variable like currentPage

<variable name="currentPage" class="java.lang.Integer" resetType="Page">
        <variableExpression><![CDATA[$V{PAGE_NUMBER}]]></variableExpression>
    </variable>

for a field to print only on last page have expression like 

$V{currentPage}.equals( $V{PAGE_NUMBER} ) ? $F{fieldName} : ""

and set evaluation time  = Auto

srins.9's picture
155
Joined: Aug 28 2015 - 8:11am
Last seen: 5 years 6 months ago
Feedback