我正在编写一个非常简单的示例项目来熟悉 Jasper Reports。我想将我配置的报告导出为 PDF OutputStream
,但没有工厂方法:
InputStream template = JasperReportsApplication.class
.getResourceAsStream("/sampleReport.xml");
JasperReport report = JasperCompileManager.compileReport(template);
JasperFillManager.fillReport(report, new HashMap<String, String>());
// nope, just chuck testa.
//JasperExportManager.exportReportToPdfStream(report, new FileOutputStream(new File("/tmp/out.pdf")));
如何在 OutputStream
中获取 PDF?
最佳答案
好的,这就是它的工作原理; JasperFillManager
实际上返回一个 JasperPrint
对象,所以:
// get the JRXML template as a stream
InputStream template = JasperReportsApplication.class
.getResourceAsStream("/sampleReport.xml");
// compile the report from the stream
JasperReport report = JasperCompileManager.compileReport(template);
// fill out the report into a print object, ready for export.
JasperPrint print = JasperFillManager.fillReport(report, new HashMap<String, String>());
// export it!
File pdf = File.createTempFile("output.", ".pdf");
JasperExportManager.exportReportToPdfStream(print, new FileOutputStream(pdf));
享受。
关于java - 将 JasperReport 导出为 PDF 输出流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8568945/