0
votes

The problem is when I generate the pdf report by using Eclipse IDE finished, the pdf report will display only current page number but total page number not show because it's more than 100 pages(less than 100 pages will display).It's only show on preview in jaspersoft studio fine. I use expression for display total page is $V{PAGE_NUMBER} and set evaluation time to be "Report". I use expression for display current page number is $V{PAGE_NUMBER} + " OF " and set evaluation time to be "Now". I use TIBCO Jaspersoft® Studio 6.6.0. Can anybody help me. Thank you

//generate pdf report code
File reportFile = new File(jrxml_path + criteria.getReportCode() + ".jrxml");
FileInputStream inputStream = new FileInputStream(reportFile); 
JasperPrint jasperPrint = JasperFillManager.fillReport(JasperCompileManager.compileReport(inputStream), params, connection);

 //in pom.xml file
    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>6.6.0</version>
    </dependency>
1

1 Answers

0
votes

I found the cause of problem because I use JRSwapFileVirtualizer in java code. The virtualizer will cut the jasper print into different files to avoid out of memory exception and save them on the hard drive and/or compress it, so the total page cannot to calculate because I set maxSize parameter to be 100 pages.

Integer virtualPage         = 100; 
Integer virtualBlockSize    = 2048;     
File virtualizePath = new File(report_path + "virtual");

JRSwapFile swapFile = new JRSwapFile(virtualizePath.getAbsolutePath(), virtualBlockSize, 100);
virtualizer = new JRSwapFileVirtualizer(virtualPage, swapFile);
virtualizer.setReadOnly(true);
JRVirtualizationHelper.setThreadVirtualizer(virtualizer);
params.put(JRParameter.REPORT_VIRTUALIZER, virtualizer);

If you want to read more about virtulizers in JasperReports, you can go to this link: virtualizers-jasperreports