Combine multiple jasper reports to single / Batch Export

Combine multiple jasper reports to single / Batch Export



Solution1:

JasperPrint[] jasperPrint = new JasperPrint[jaspers.length];
for (int i=0; i<jaspers.length; i++) {
   JRDataSource ds = //code for ds creation.
   Map jasperParams = //include report parameters
   jasperPrint[i] = JasperFillManager.fillReport(jaspers[i],jasperParams, ds)
}
JRAbstractExporter exporter = //code for export creation
exporter.setParameter(... //code for exporter parameters
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrint);
exporter.exportReport();
</td></tr></tbody></table>

Solution2:
batchexport sample"


Solution3:
jasperPrint = JasperFillManager.fillReport(jasperReport, jasperParameter, con);
list.add(jasperPrint); 
exp.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, list);
exp.setParameter(JRPdfExporterParameter.OUTPUT_FILE, new File("test.pdf"));
exp.exportReport();



Solution4:
You can take advantage of exporting the whole jasperprint list:
List jpList = new ArrayList();
jpList.add(JRLoader.loadObjectFromFile("build/reports/Report1.jrprint")); 
...
JRExporter exporter = new JRPdfExporter(); 
exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, jpList); 
exporter.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, stream); 
exporter.exportReport();
 
 


Solution5:

I just want to show several JasperPrint Objects in only one JRViewer. Is
there a function to concat 2 or more JasperPrint Objects to one JasperPrint
Object? or something like that?

In pseudo code:
JasperPrint jp1 = JasperFillManager.fillReport(url.openStream(), parameters,
                    new JRBeanCollectionDataSource(inspBean));
JasperPrint jp2 = JasperFillManager.fillReport(url.openStream(), parameters,
                    new JRBeanCollectionDataSource(inspBean));
JasperPrint jp = jp1+jp2

jrviewer= new JRViewer(jp);


 
unfortunately the solution is build a sub report and use the 2 different DataSource or what ever connection you used




but there is an easy way to get over with this question :D
just simple no new reports ..... Wolaah
 

ok lets do it


JasperPrint jp1 = JasperFillManager.fillReport(url.openStream(), parameters,
                    new JRBeanCollectionDataSource(inspBean));
JasperPrint jp2 = JasperFillManager.fillReport(url.openStream(), parameters,
                    new JRBeanCollectionDataSource(inspBean));


ok we have over 2 records ..lets take our first record  
jp1 and add jp2 content into it
  
List pages = jp2 .getPages();
            for (int j = 0; j < pages.size(); j++) {
            JRPrintPage object = (JRPrintPage)pages.get(j);
            jp1.addPage(object);
       
    }
    JasperViewer.viewReport(jp1,false);


This work like a charm .. with couple of loops you can merge any number of report together .. without creating new reports  
Solution6:
JasperReport jr1 = (JasperReport) JRLoader.loadObject(...);
JasperReport jr2 = (JasperReport) JRLoader.loadObject(...);
 
JREmptyDataSource ds = new JREmptyDataSource(1);
JasperPrint print1 = JasperFillManager.fillReport(jr1, new HashMap(), ds);
 
ds.moveFirst();
 
JasperPrint print2 = JasperFillManager.fillReport(jr2, new HashMap(), ds);
List l = new ArrayList();
 
l.add(print1);
l.add(print2);
 
JRPdfExporter exp = new JRPdfExporter();
exp.setParameter(JRExporterParameter.JASPER_PRINT_LIST, l);
exp.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, SAVE_LOCATION);
exp.exportReport();
 
 
Solution7:

I looked at Jasper Reports, the defacto standard, but it seemed like I would only be able to create a multiple page PDF document that shared the same template. What's worse is that Jsaper Reports enforces a maximum height of 738 px in the detail section of the report. This meant I couldn't use page breaks to give each page its own unique look and feel.

After a little more reading, I discovered that Jasper Reports can generate PDF reports in "batch mode". Batch mode allows you to concatenate several reports together into a single File or OutputStream.

To use batch mode you must add your List of JasperPrint objects to the
JRExporterParameter.JASPER_PRINT_LIST parameter of the exporter.

Example:
ArrayList
 jasperPrintList = [Your logic for creating the list]

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

JRPdfExporter exporter = new JRPdfExporter();

exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList);
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, outputStream);

exporter.exportReport();

inputStreamForStruts2 = new ByteArrayInputStream(outputStream.toByteArray());

Post a Comment

Thank You

Previous Post Next Post