Jump to content
Changes to the Jaspersoft community edition download ×

Clean Page X of Y ?


rsilverns.sympatico.ca

Recommended Posts

Just wondering if anyone knows of a clean way to do a page numbering in format of "Page X of Y"? I am able to do it currently by having two expressions, "Page X of" which gets evaluated at "now" and then "Y" which gets evaulated once at the end to calculate each page.

Code:
<textField>
<reportElement x="390" y="6" width="99" height="20"/>
<textElement textAlignment="Right"/>
<textFieldExpression class="java.lang.String"><![CDATA["Page " + $V{PAGE_NUMBER} + " of "]]></textFieldExpression>
</textField>
<textField evaluationTime="Report">
<reportElement x="489" y="6" width="15" height="20"/>
<textElement textAlignment="Left"/>
<textFieldExpression class="java.lang.Integer"><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
</textField>

 

 

The problem is that it really makes aligning the page numbering hard since they are two text fields and the total page count could grow considerably depending on the data set. I would like to know if anyone knows of tricks for how to best create this page numbering? I would like to have a smooth spacing and alignment of "Page X of Y" so that I could right align the entire thing on the right side of my page at the right margin... and have it grow to the left as needed (i.e. Page XX of YYY etc.)

 

Thx,

Robin

Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

That fixed it.. nice trick guys!

 

For those reading this post, as per lucianc's other post the solution was.....

 

 

Code:
<variable name="CurrPageNo" class="java.lang.Integer" resetType="Page">
<variableExpression>$V{PAGE_NUMBER}</variableExpression>
</variable>
..
<textField evaluationTime="Auto">
..
<textFieldExpression><![CDATA["Page " + $V{CurrPageNo} + " / " + $V{PAGE_NUMBER}]]></textFieldExpression>
</textField>

 

Thanks,

Robin

Link to comment
Share on other sites

I may have spoken too soon... this trick works for reports that do not have "Pages" introduced by the false group header trick, but when you do that the system breaks down and I have a "null" generated for each page except the last page for the X in Page X of Y.

 

Am seeing an infinite loop introduced during report filling somehow. Not sure what is going on will attempt to debug it. Will add this as a feature request.

Link to comment
Share on other sites

I'm not sure what the "false group header trick" is. And what exactly happens? You mentioned that "the system breaks down", then that you get "null" instead of the current page, and then you said something about an infinite loop.

 

Do you have a simple sample (or relevant JRXML fragment) that illustrates the issue?

 

Regards,

Lucian

Link to comment
Share on other sites

  • 6 months later...

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