9
votes

I have added the footer Page x of y to my report, but the PAGE_COUNT doesn't seem to work.

Maybe the problem occurs because I have many subreports?

I get:

Page 1 of 1

Page 2 of 0

Page 3 of 0

Page 4 of 0

Any ideas?

8

8 Answers

11
votes

Well, don't know elder versions but in JasperReports 4.5.1; you can define two text fields both includes $V{PAGE_NUMBER} variables. The one which has EvaluationTime: now shows current page number; the other one with EvaluationTime: report shows the number of total pages. A simple trick but works :)

6
votes

Changing the evaluationTime="Report" solved the problem.

2
votes

I found the solution.

http://jasperforge.org/tracker/index.php?func=detail&aid=2873&group_id=102&atid=612

But the book JasperReports for Java Developers (p 146) says that PAGE_COUNT is the total number of pages in the report. I guess the bug is in the book.

2
votes

Actually It Is a BUG! And confirmed by developers.

See link: jasper community bug tracker link

PAGE_COUNT is not correctly calculated, when using property on BAND: "Split Prevent"

2
votes

our reports look like :

http://pastebin.com/m401fa41

1st part, interpreted during page generation, gives the # of the current page (evaluationTime="Now")

2nd part, interpreted at the end of the report , gives the total # of pages (evaluationTime="Report")

HTH

2
votes

The solution is the follow : We must not put $ { V PAGE_NUMBER }+ "/" + $ { V } PAGE_NUMBER in the same field.

the proper way is to put $ { V PAGE_NUMBER } in separated field and "/ " + $ { V } PAGE_NUMBER in the other field

it work for me

sorry for my english

2
votes

Summary: To have the page number and the page number in a TextField.

Step 1: Create a variable that indicates the number of the current page.      Settings: * Name: CURRENT_PAGE_NUMBER

  • Variable class: Java.lang.Integer

  • Calculation: nothing

  • Reset Type: None

  • Increment type: Page

  • Variable Expression: $ V {CURRENT_PAGE_NUMBER} == null? $ V {PAGE_NUMBER}: $ V {PAGE_NUMBER} +1

Step 2: TextField Settings

  • Text Field Expression: "PAGE:" + $ V {CURRENT_PAGE_NUMBER} + "/" + $ V {PAGE_NUMBER}

  • Expression class: Java.lang.String

  • Evaluation Time: Auto

And that's all. No need to add anything to it to give you a result like: Page 1/3 | Page 2/3 | Page 3/3.

1
votes

I haven't access to the jaspercommunity (to check the link shared), but I do a good workaround :D

Use 4 texts, like this:

txtStatic1(Page) txtField1($V{PAGE_NUMBER})  txtStatic2(of) txtField2($V{PAGE_NUMBER})

Where:

txtField1($V{PAGE_NUMBER}) -> AVAILABLE TIME = PAGE
txtField2($V{PAGE_NUMBER}) -> AVAILABLE TIME = REPORT

It's works to me.