我可以在单个PDF文件中打印多个报告。
使用:
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();
所以问题是:
(这里为每个报告在我的pdf中添加新页面。) 如何在PDF的单页上打印此所有报告的所有数据。
答案 0 :(得分:5)
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();
答案 1 :(得分:2)
答案 2 :(得分:1)
这个怎么样?
JRExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, new FileOutputStream("c:/mipdf.pdf"));
//The following is the important line
exporter.setParameter(JRExporterParameter.JASPER_PRINT_LIST, Arrays.asList(jasperPrint, jasperPrint));
exporter.exportReport();
像魅力一样工作!
答案 3 :(得分:0)
您可以使用这个。首先合并您的报告并导出为pdf。
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, dataSource);
JasperPrint jasperPrint1 = JasperFillManager.fillReport(jasperReport1,
parameters, dataSource1);
List<JRPrintPage> pages = jasperPrint1.getPages();
for (int j = 0; j < pages.size(); j++) {
JRPrintPage object = (JRPrintPage)pages.get(j);
jasperPrint.addPage(object);
}
JasperExportManager.exportReportToPdfStream(jasperPrint, outputStream)
这是通用解决方案。