Robert Ensinger

How To: Single Textbox "Page {X} of {Y}" Page Counts in Jaspersoft Reports

Blog Post created by Robert Ensinger on Dec 28, 2015

When migrating our reports from Business Objects to Jaspersoft it's important for us to abide by our documented reporting standards, retaining the same look & feel that our customers are familiar with.


In our reporting standards the page count information is found in the page footers as shown below. "Page X of Y" in the report footer, bottom right, aligned right with room to grow left.


Jaspersoft's PAGE_NUMBER variable & functionality is designed as a two textbox solution for "Page X of Y" results.


This doesn't lend itself easily to clean align left or align right visualizations. To do this we need to Display "Page 1 of N" In a Single Text Field. Here's how.


1) Create a new Integer Variable called CURRENT_PAGE_NUMBER that inherits $V{PAGE_NUMBER} via its expression, with no calculation or increment type as shown below. Be sure to set the Reset type to Page.


2) Add a Text Field to your page, set the Evaluation Time to Auto as shown below, text alignment as you wish and add the expression:





3) Save & Preview your report. You should now see the Page X of Y message in one text box, aligned as expected.



<variable name="CURRENT_PAGE_NUMBER" class="java.lang.Integer" resetType="Page">


<textField evaluationTime="Auto">
 <reportElement x="460" y="10" width="100" height="20" uuid="60626a70-961a-40c3-ba86-6e72046e405a">
   <property name="" value="pixel"/>
   <property name="" value="pixel"/>
   <property name="" value="pixel"/>
  <textElement textAlignment="Right" verticalAlignment="Middle"/>
  <textFieldExpression><![CDATA["Page "+ $V{CURRENT_PAGE_NUMBER} + " of " + $V{PAGE_NUMBER}]]></textFieldExpression>