How to combine several JasperPrint objects to have one report with mixed page orientation

后端 未结 1 1468
萌比男神i
萌比男神i 2021-01-12 16:01

The jasperPrint object has portrait orientation, but jasperPrint2 object has landscape orientation. I want to combine the two jasperprints to produ

1条回答
  •  伪装坚强ぢ
    2021-01-12 17:00

    You can accomplish this by doing a batch export.

    //put all the jasperPrints you want to be combined into a pdf in this list
    List jasperPrintList = new ArrayList();
    
    JasperReport report = (JasperReport) JRLoader.loadObject(reportFile2.getPath());
    jasperPrintList.add(JasperFillManager.fillReport(report, parameters, conn));
    
    JasperReport report2 = (JasperReport) JRLoader.loadObject(reportFile.getPath());
    jasperPrintList.add(JasperFillManager.fillReport(report2, parameters, conn));
    
    ByteArrayOutputStream baos = new ByteArrayOutputStream();       
    JRPdfExporter exporter = new JRPdfExporter();       
    //this sets the list of jasperPrint objects to be exported and merged
    exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jasperPrintList);
    //the bookmarks is a neat extra that creates a bookmark for each jasper print
    exporter.setParameter(JRPdfExporterParameter.IS_CREATING_BATCH_MODE_BOOKMARKS, Boolean.TRUE);
    exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);     
    exporter.exportReport();        
    return baos.toByteArray();
    

    0 讨论(0)
提交回复
热议问题