Jump to content
Changes to the Jaspersoft community edition download ×

print when for last page


jwindberg

Recommended Posts

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})

Link to comment
Share on other sites

  • Replies 18
  • Created
  • Last Reply

Top Posters In This Topic

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!!!!!

Link to comment
Share on other sites

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:

<variable name="currentPage" class="java.lang.Integer" resetType="Page">
<variableExpression>$V{PAGE_NUMBER}</variableExpression>
</variable>
..
<background>
..
<image evaluationTime="Auto">
<imageExpression>$V{currentPage}.equals($V{PAGE_NUMBER}) ? your_image : null</imageExpression>
</image>
..
</background>

 

HTH,

Lucian

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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/FAQ12

 

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

Link to comment
Share on other sites

  • 2 years later...

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?

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

  • 7 months later...
  • 1 month later...

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

 

Link to comment
Share on other sites

  • 2 months later...
  • 7 years later...

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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...