Page Numbers

So, I can't figure out why it's so difficult/annoying to use page numbers in iReport, surely there's an easier way?

The current method I'm employing is actually having 2 text fields! 1 is have $V{PAGE_NUMER} and is evaluated "Now", giving me the current page, then another with $V{PAGE_NUMER} evaluated at "Report", giving me to total number.

Of course having 2 text fields absolutely ruins the formatting! You end up with inconsistent spacing between the 2 text fields, when you've got a single digit you have a larger gap than a double digit! It's ridiculous, surely there's a better way???

cameron_1's picture
Joined: May 5 2013 - 8:32pm
Last seen: 5 years 10 months ago

2 Answers:



Instead of using two text fields, one with evaluationTime=Now and the other with evaluationTime=Report, you could use only one text field with evaluationTime=Auto.

In order for this to work, you need to use in your expression two variables that have different resetType levels.

The build-in PAGE_NUMBER variable is good for the total number of pages. But for the current page number, you need a custom made variable, let's call it CRT_PAGE_NUMBER, which has calculation=Nothing and resetType=Page, which copies the value of the PAGE_NUMBER variable in its expression.

I hope this helps.


teodord's picture
Joined: Jun 30 2006 - 9:00am
Last seen: 3 hours 35 min ago

Perfect, exactly what I was after!

This should be documented somewhere, for future reference!

cameron_1 - 9 years 7 months ago

I am getting a null value for the CRT_PAGE_NUMBER. Do you have idea how can this be fixed?

erickdelsocorro - 6 years 3 months ago

Getting the same null value for the CRT_PAGE_NUMBER. Is there something I am missing?

wreynkens - 6 years 2 months ago


I solved this problem with "reparsing" the resulting JasperPrint-Object (so all elements at each page) and set my "Page #X# of #Y#" Placeholder with the corresponding values from final JasperPrint - works fine and fast (< 1sec) and solves the same layout problems that you also have.

Of course this works only with JasperReports API and also not with Groups that have their own PageNumbering (ResetPageNumber flag set) - but this is not needed for my case.

When I remember right someone posted also a pure variable (so no API coding needed) solution with a StackVariable that is calculated at each Page and a textfield that uses this StackVariable with evaluationtime = report .. but this was also quite tricky and not a "end user" solution where no JasperReports gurus just want to place some fields at report. (use search function for this forum)


regards from rainy Germany



C-Box's picture
Joined: Jul 19 2006 - 5:58pm
Last seen: 5 months 2 weeks ago