将JasperReport导出到PDF OutputStream?
我正在编写一个非常简单的示例项目,以使自己熟悉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")));
如何在中获取PDF OutputStream
?
回答:
好的,这就是它的工作原理。JasperFillManager
实际上返回一个JasperPrint
对象,因此:
// get the JRXML template as a streamInputStream 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));
请享用。
以上是 将JasperReport导出到PDF OutputStream? 的全部内容, 来源链接: utcz.com/qa/413158.html