在我的 Java 网络应用程序中,我确实生成了一份报告,每个客户检测到一页。
我创建了一个 JasperReport,如果客户列表超过 1 个,我想合并生成的报告。
这是我的代码:
if(myList.size()==1) {
JasperPrint jp = reportGenerated(myList.get(0).getCustomer());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
JasperExportManager.exportReportToPdfStream(jp, bos);
return bos.toByteArray();
}else {
for(Object s: myList) {
jasperPrints.add(reportGenerated(s.getCustomer()));
}
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
JRPdfExporter exporter = new JRPdfExporter();
exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrints));
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("pdf/lettera.pdf"));
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setCreatingBatchModeBookmarks(true);
exporter.setConfiguration(configuration);
exporter.exportReport();
}
我想获取合并后的PDF,但在ByteArrayOutputStream中找不到导出JasperPrint列表的功能。
有什么建议吗?
最佳答案
尝试改变:
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("pdf/lettera.pdf"))
与:
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(bos));
并添加返回语句:
return bos.toByteArray();
我认为这个解决方案可以帮助您。
关于java - 创建合并的 JasperReport 的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51404694/