将JasperReport导出为PDF OutputStream? [英] Export JasperReport to PDF OutputStream?

查看:1355
本文介绍了将JasperReport导出为PDF OutputStream?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个非常简单的示例项目,用于熟悉Jasper Reports。我想将我配置的报告导出为PDF OutputStream ,但是它没有工厂方法:

I'm writing a pretty simple sample project for familiarizing myself with Jasper Reports. I'd like to export a report I've configured to a PDF OutputStream, but there's no factory method for it:

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 对象,所以:

Ok, so here's how it works; JasperFillManager actually returns a JasperPrint object, so:

// 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));

享受。

这篇关于将JasperReport导出为PDF OutputStream?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆