【问题标题】:How to use Grails with BIRT report and show BIRT web viewer如何将 Grails 与 BIRT 报告一起使用并显示 BIRT Web 查看器
【发布时间】:2011-04-14 09:09:25
【问题描述】:
我在 Grails Web 应用程序项目中安装了 birt-report 插件,但我无法理解如何使用它。我有 2 个用例:
- 生成 BIRT Web 查看器并在 GSP 页面上显示(显示图表报告)
- 将 BIRT 报告生成为其他文件格式(PDF、Word 等)
任何人都可以提供如何做到这一点的例子吗?
【问题讨论】:
标签:
grails
grails-plugin
birt
【解决方案1】:
基本上,您可以使用插件文档 (http://grails.org/plugin/birt-report) 中提到的示例。
1.用于生成HTML报告使用。注意到 BIRT 生成 HTML 而不是 GSP。您可以在 GSP 页面中呈现输出 HTML。
// generate html output and send it to the browser
def show() {
String reportName = params.remove('id')
String reportExt = 'pdf'
params.remove('action')
params.remove('controller')
params.remove('name')
def options = birtReportService.getRenderOption(request, 'html')
def result=birtReportService.runAndRender(reportName, params, options)
response.contentType = 'text/html'
response.outputStream << result.toByteArray()
return false
}
-
生成 pdf 供下载
def 下载AsPDF() {
字符串报告名称 = params.remove('id')
字符串报告扩展 = 'pdf'
params.remove('动作')
params.remove('控制器')
params.remove('名字')
def options = birtReportService.getRenderOption(request, 'pdf')
def 结果=birtReportService.runAndRender(报告名称,参数,选项)
response.setHeader("Content-disposition", "attachment; filename=" +reportName + "."+reportExt);
response.contentType = '应用程序/pdf'
response.outputStream