Jump to content
We've recently updated our Privacy Statement, available here ×

Export JasperPrint with & without IgnorePagination


hq4ever

Recommended Posts

Hello,

I'm trying to export a JasperPrint into 2 format first : HTML which should have no pagination in the reports, second PDF which should obviously have pagination enabled.

I'm aiming at not fillwing the "same" report twice, thus avoiding the costly DB queries operation.

 

My current (not optimal) solution is to use 2 seperate calls to the reporting framework, my code looks something like this:

 

                     for(JasperReportType reportType : JasperReportType.values()) {
                        if(reportType == JasperReportType.HTML || reportType == JasperReportType.HTML_ONLY || reportType == JasperReportType.CSV_SPECIAL_FORMAT) {
                            jasperDesign.setIgnorePagination(true);
                        } else {
                            jasperDesign.setIgnorePagination(false);
                        }
                        
                        JasperCompileManager.compileReportToFile(jasperDesign, fsRoot + jasperFile + "-" + reportType + ".jasper");
                    }
 

Later on I load the appropreate .jasper file and print it.

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

There's no good solution for that.

Report pagination is performed at fill time, so you will have to fill the report twice.  If you don't want to execute the report query twice, there are a few approaches that you can take:

  1. Execute the query yourself and wrap the result set twice in JRResultSetDataSource instances (you will have to do something like beforeFirst() to move the cursor back to the first row).  But that might result in fetching the data twice from the DB.
  2. If the you don't have a large data set, you can execute the query and read the result set into Java objects that you can then send as data source to the reports.
  3. If you're the adventurous type, you can also try to write a data source implementation that can be used to fill several reports simultaneously.  That's theoretically possible (the data source can block on next() calls until all reports ask for the next record), but not trivial to implement.

Note that all these require you to run the query yourself, so you would not use the JR support for parameters/etc.

Also there are some cases in which a paginated report can be exported to HTML and CSV with its page headers/footers excluded so that it looks like an unpaginated report.  But this approach needs some assumptions on the report, so it doesn't always work.

Regards,

Lucian

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