Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
How to download a pdf or open a pdf in new tab
Trackbrood
<p>Hi All,</p><p> </p><p>i have integrated birt 4.2.2 in spring 3.1 in a web application, generating pdf opens the pdf in the same browser window, but i want to give options like save before opening the pdf. </p><p> </p><p>code used for pdf generation </p><p> </p><div>PDFRenderOption pdfOptions = new PDFRenderOption(options);</div><div>pdfOptions.setOutputFormat(PDFRenderOption.OUTPUT_FORMAT_PDF);</div><div>pdfOptions.setOption(IPDFRenderOption.PAGE_OVERFLOW,</div><div>IPDFRenderOption.FIT_TO_PAGE_SIZE);</div><div>pdfOptions.setOutputStream(response.getOutputStream());</div><div>runAndRenderTask.setRenderOption(pdfOptions);</div><div> </div><div>i am using following code for excel, which gives me the options to open save and cancel in windows machine.</div><div> </div><div><div>EXCELRenderOption excelOptions = new EXCELRenderOption(options);</div><div>excelOptions.setOutputFormat("xls");</div><div>excelOptions.setOfficeVersion(EXCELRenderOption.OUTPUT_FORMAT);</div><div>excelOptions.setOutputStream(response.getOutputStream());</div><div>runAndRenderTask.setRenderOption(excelOptions);</div><div> </div><div>i wanted the same options(open, save, cancle) for pdf as well</div><div> </div><div>please help</div><div> </div><div>Thanks,</div><div>Amit</div><div> </div><div> </div><div> </div></div><p> </p>
Find more posts tagged with
Comments
idonaldson
<p>I have a method that downloads a pdf, it's written in grails/groovy code, but it works and might give you some direction?</p><p> </p><p>This is the method that our UI calls in our controller, which then goes to a method much like the one you have.</p><pre class="_prettyXprint">def downloadAsPDF() { String reportName = params.remove('id') String reportExt = 'pdf' 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 }</pre><p>Hopefully this helps, let me know if you want to see the runAndRender method in our plugin as well.</p><p> </p><p>-Ian</p>