Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i print multiple jasper report in single page of PDF

I can print multiple reports in the single PDF file using the below code, but it's adding a new page per report.

JasperReport jreport1 = JasperCompileManager.compileReport("D:\\FTP\\JRXML\\PatientConsultantReport\\"+checkedReport+".jrxml");
JasperPrint jprint1 = JasperFillManager.fillReport(jreport1, new HashMap(), new JRResultSetDataSource(rs));
jprintlist.add(jprint1);
          .
         So ON
          .
          .
jprintlist.add(jprint5);

    JRExporter exporter = new JRPdfExporter();
                exporter.setParameter(JRPdfExporterParameter.JASPER_PRINT_LIST, jprintlist);
                OutputStream output = new FileOutputStream(new File("D:\\FTP\\PDF\\VisitsSummaryReport.pdf"));
                exporter.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, output);
                exporter.exportReport();

So Question is: How can I print all data on a single page of PDF, instead of having a new page per report?

like image 894
HybrisHelp Avatar asked Dec 09 '22 13:12

HybrisHelp


1 Answers

List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>();

// Create multiple jasper prints and add to a list
HashMap<String, Object> params = new HashMap<String, Object>();
InputStream inputStream1 = this.getClass().getResourceAsStream("template1.jrxml");
JasperDesign jd1 = JRXmlLoader.load(inputStream1);
JasperReport jr1 = JasperCompileManager.compileReport(jd1);
JasperPrint jp1 = JasperFillManager.fillReport(jr1, params);
jasperPrintList.add(jp1);

InputStream inputStream2 = this.getClass().getResourceAsStream("template2.jrxml");
JasperDesign jd2 = JRXmlLoader.load(inputStream2);
JasperReport jr2 = JasperCompileManager.compileReport(jd2);
JasperPrint jp2 = JasperFillManager.fillReport(jr2, params);
jasperPrintList.add(jp2);

// Generating report using List<JasperPrint>
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(new ByteArrayOutputStream()));
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setCreatingBatchModeBookmarks(true);
exporter.setConfiguration(configuration);
exporter.exportReport();
like image 109
Nevin Avatar answered Dec 11 '22 09:12

Nevin