Hello,
We are using JasperReports 3.7.1 and have three reports, which are already compiled. They will be merged to one PDF File with JasperExportManager.
In the PDF File it says:
- First report: 1 to 3 pages
- Second report: 1 to 10 pages
- Third report: 1 to 5 pages.
The requirement is that in the PDF is one numberation, in this case 1 to 18 pages. How can you count the pages although there are three seperate reports?
Thanks in advance,
jrcate
4 Answers:
Hi,
This is a simplified example with 2 reports, Report1 and Report2:
- in the Report2.jrxml declare a report parameter:
<parameter name="initialPageValue" class="java.lang.Integer"/>
- in the Report2.jrxml use a modified expression for the textfield containing the page number :
<textFieldExpression class="java.lang.String"><![CDATA["Page " + ($P{initialPageValue} + $V{PAGE_NUMBER})]]></textFieldExpression>
- at report filling time, see the code area below.
HTH,
sanda
Code: |
Map parameters1 = new HashMap(); // set your parameters here JasperPrint jPrint1 = JasperFillManager.fillReport( "Report1.jasper", parameters1, <your_JRDataSource_here> ); Map parameters2 = new HashMap(); // set your parameters here parameters2.put("initialPageValue", jPrint1.getPages().size()); JasperPrint jPrint2 = JasperFillManager.fillReport( "Report2.jasper", parameters2, <your_JRDataSource_here> ); // process the reports further </td></tr></tbody></table> |
With @shertage's solution alone we cannot number the pages "1 of 5", because report 1 does not know how many pages the second report will have. You get
1 of 3
2 of 3
3 of 3
4 of 5
5 of 5
My solution to this was to fill the first report twice:
- Build report 1, page count 3 in this example. You have to use the real data source to know how many pages it will be. Throw away the JasperPrint that results.
- Build report 2, initial page count 3, adds pages 4 of 5 and 5 of 5.
- Build report 1 again, passing in initial page count of 3 + report 2's page count of 2 = total page count 5.