I would like to create one text field that contains Page X of Y
, without splitting it in two parts, as per the common solution. My textfield contains "Page " + $V{currentPage} + " of " + $V{PAGE_NUMBER}"
with evaluationTime=auto
.
Let's say I have a report with 10 pages. Three are the Title Band, six are Detail Band and one is the Summary Band. My results show "Page 0 of 10"
for the Title Bands, correct counts for the Detail Bands, then "Page 0 of 10"
for the Summary Bands.
How do you ensure the variable is calculated everywhere, not only on Detail Band?
you have to use page footer band for that, set the $V{PAGE_NUMBER} 's print when expression to "REPORT" when you have to display total pages and, $V{PAGE_NUMBER} 's print when expression to "NOW" when you have to display current page number.
For showing the page number on the last page of the report the Last Page Footer band must be added by right clicking on it in iReports in the left panel called Report Inspector.
For Jaspersoft Studio v6, or if the first page number is duplicated, try this solution, which uses $V{MASTER_CURRENT_PAGE}
and $V{MASTER_TOTAL_PAGE}
with an evaluation time of Master
.
For other versions of Jaspersoft Studio, try the steps outlined in the subsequent subsections.
Create a variable as follows:
V_CURRENT_PAGE_NUMBER
1
$V{PAGE_NUMBER}
0
, use $V{PAGE_NUMBER} + 1
.1 of Y
, set Expression to $V{PAGE_NUMBER}
instead of the initial value expression, and leave the initial value expression empty.Page
These settings are illustrated in the following figure:
Setting the Expression to 1
prevents its value from being null
. That is, if the footer shows Page null of 4 it probably means that the Expression hasn't been set.
The variable is created.
Add a Page Footer band as follows:
The footer is added.
Create a text field as follows:
msg("Page {0} of {1}", $V{V_CURRENT_PAGE_NUMBER}, $V{PAGE_NUMBER})
Auto
These settings are illustrated in the following figure:
The single text field is created.
For a report with three pages plus a summary page, previewing the report shows:
The summary page shows:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With