Jump to content
Changes to the Jaspersoft community edition download ×

Getting the total number of pages in a report


peter_tonev

Recommended Posts

Hello community,

 

I'm looking for a way to evaluate the total number of pages in a Jasper Report. I.e. NOT to render but to process it (!).

I know it is possible to render the total number of pages using the variable $V{PAGE_NUMBER} in a text field with evaluation time "Report". This isn't what I need - I need really to get the value of the varaible $V{PAGE_NUMBER}, evaluated within the "Report" scope, and use this value further (e.g. in expressions of elements placed in the page footer).

Is this possible with JasperReports?

 

Thanks & regards,

Peter

 

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi,

It all depends on what you actually want to do with the total number of pages. You can get that value only inside text field expression, because in JR, this is a feature of text field elements.

We call this "late fill" capability and is controlled using the evaluationTime property of text field elements.

So if you want to leverage the total number of pages to conditionally display some values in page footer, that should be OK.

But if you want to use it in variables calculations and things that have the potential of changing the total page number itself, that is not possible.

 

Imagine you use the total number of pages to display or not a subreport. Well, if that would be possible (is not) it means the the appearence of the subreport could affect the already calculated page total, which does not make sense.

 

II hope this helps.
Teodor

 

Link to comment
Share on other sites

Hi Teodor,

 

thanks a lot for your reply. I feared it would seem this way.

 

I think I'd better describe what we exactly are trying to do.

 

We have reports which are embedded in our web application using the REST API. Primary usage of our app is on iPads, where the available system ressources are limited, so our app have to be very performant.

Some of our reports can get very long (for our limitations) - about 20-30 pages, and then the app page starts to flutter upon actions like swiping, scrolling a.s.o. Along with this, the app gets very slow.

As a workaround we decided to introduce pagination in our reports for we noticed that the fluttering issue doesn't take effect when having only one-page reports.

We don't use the Jasper page-scrolling buttons for two reasons: as said, we deploy the REST interface and fetch the reports as HTML content using the XHTML exporter (so the JasperServer page scrolling buttons simply aren't there); and then we want the embedded Jasper reports to look like the rest of our application, so we use customisable elements like HTML elements, images or text.

 

Now, the idea was that our reports offer hyperlink-based buttons << previous | next >>. On click the << next >> button increments the REST parameter "page" by 1.

I.e. the hyperlink defined on the "next" button is a REST request for the same report with a certain page, and I attach to the url the string

"&page=".concat($V{varNextPage})

where varNextPage is defined as

($V{PAGE_NUMBER} + 1).toString()

A varPrevoiusPage would then be accordingly.

($V{PAGE_NUMBER} - 1).toString()

Now, in order not to get out-of-index error, we needed to define what happens if you're already on the first or the last page and try to go further.

 

The <> -button was easier, for the first page has obviously the number 1, so I used for the varPrevoiusPage the expression:

(

$V{PAGE_NUMBER} - 1 < 1

? "1"

: ($V{PAGE_NUMBER} - 1).toString()

 

)

I.d. if you're on the first page already and you click "previuos", you get the first page once again. (What is also possible would be to supess the <>-button when on first page.

 

The hard part comes with the <>-button when you're already on the last page. Our issue is how to tell if you're on the last page. Supposed there was a variable called e.g. TotalPageCount which gives us this value, we could define our varNextPage like

(

$V{PAGE_NUMBER} + 1 > TotalPageCount

? $V{PAGE_NUMBER}

: ($V{PAGE_NUMBER} + 1).toString()

 

)

Then on click on the <>-button as you are already on the last page, you'd just stay there (or you could supress the "next"-button based on the expression $V{PAGE_NUMBER} == TotalPageCount).

 

I know such features from Crystal Reports, where you could define formula like (PageNumber = TotalPageCount), or user the Next function to get the next record, NextIsNull function to test it the next record value is NULL, all this together with functions for delayed evaluation like whilePrintingRecords, evaluateAfter a.s.o.

 

Can you propose some solution or workaround for our requirement as described above - it doesn't have to work this way we try, but rather have the same (paging) functionality within the HTML-exported report.

What would you do in our place?

 

Many thanks in advance

Peter

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