ireport中多张报表模版导出一个pdf文件

阅读更多

情景:现在有许多打印模版,根据不同的走货路线来指定模版路径,现在只能一个走货路线的打印模版批量导出到一个PDF文件。但是,客户想多个走货路线的打印模版批量导出到一个PDF文件,也就是多个报表模版导出到一个PDF文件。

解决方法:

String path = this.getServletContext().getRealPath("/");
JasperPrint jasperPrint = JasperFillManager.fillReport(path+"Pilipinas_hot.jasper",new HashMap(), new JREmptyDataSource());
JasperPrint jasperPrint2 = JasperFillManager.fillReport(path+"Malaysia_hot.jasper",new HashMap(), new JREmptyDataSource());
List jasperPrintList = new ArrayList();
jasperPrintList.add(jasperPrint);
jasperPrintList.add(jasperPrint2);
//获取输出字节流
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST,jasperPrintList);//设置多个报表模版
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);//获取pdf文件流
exporter.exportReport();
byte[] bytes= baos.toByteArray();
FileOutputStream fos = new FileOutputStream(new File("D://test.pdf"));
fos.write(bytes);
fos.flush();
fos.close();

 

你可能感兴趣的:(ireport,ireport中多张报表模版,微风)