Reputation: 121
I installed the birt-report plugin on a Grails web application project but I cannot understand to use it. I have 2 use cases:
Can anyone please provide examples of how to do this?
Upvotes: 5
Views: 1665
Reputation: 194
Basically you can use the examples as mentioned on plugin documentation (http://grails.org/plugin/birt-report). 1. For generating HTML report use. Noticed that BIRT produces HTML and not GSP. you can render the output HTML inside your GSP page.
// 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
}
generate pdf for download
def downloadAsPDF() { String reportName = params.remove('id') String reportExt = 'pdf' params.remove('action') params.remove('controller') params.remove('name') def options = birtReportService.getRenderOption(request, 'pdf') def result=birtReportService.runAndRender(reportName, params, options) response.setHeader("Content-disposition", "attachment; filename=" +reportName + "."+reportExt); response.contentType = 'application/pdf' response.outputStream << result.toByteArray() return false }
Upvotes: 0