hq4ever Posted December 15, 2009 Share Posted December 15, 2009 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 More sharing options...
lucianc Posted December 22, 2009 Share Posted December 22, 2009 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: 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. 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. 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now