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)
Web integration - download report with ajax servlet call
easyleads
<p>Hi,</p><p> </p><p>I got Birt integrated in my web app and can use the BirtViewer successfully if I wish.</p><p> </p><p>What I really need to accomplish is the following:</p><p> </p><p>I wish to have a button in my web page that upon pressing it an <span class='bbc_underline'><strong>ajax </strong></span>call will be made to a servlet which generates a report and the report is "downloaded" as PDF/DOC/XLS -> just like if I was using the viewer</p><p>and chose to export the report. </p><p> </p><p>I see in the console that the report is generated by nothing happens in the web page..</p><p>(I am expecting the report to be "downloaded").</p><p> </p><p>Your help is greatly appreciated.</p><p> </p><p>Thanks.</p><p> </p><p> </p><p>My servlet code is:</p><p> </p><div>response.setContentType( "application/pdf" ); </div><div>response.setHeader ("Content-Disposition","inline; filename=test.pdf");<span> </span></div><div>String reportName = report.getReportName();</div><div>ServletContext sc = request.getSession().getServletContext();</div><div>//<span> </span>this.birtReportEngine = BirtEngine.getBirtEngine(sc);</div><div> </div><div> </div><div>IReportRunnable design;</div><div>try</div><div>{</div><div>IReportEngine engine = null;</div><div> EngineConfig config = null;<span> </span> <span> </span> <span> </span></div><div> // Configure the Engine and start the Platform</div><div> config = new EngineConfig();</div><div> config.setEngineHome("C:/birt-runtime-2_1_1/birt-runtime-2_1_1/ReportEngine");<span> </span> <span> </span></div><div> Platform.startup(config);</div><div> final IReportEngineFactory FACTORY = (IReportEngineFactory) Platform.</div><div> createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);</div><div> </div><div> engine = FACTORY.createReportEngine(config);</div><div> <span> </span> <span> </span> </div><div> //Open report design</div><div> design = engine.openReportDesign("C:/reports/templates/"+sourceFile); </div><div> //create task to run and render report</div><div> IRunAndRenderTask task = engine.createRunAndRenderTask(design);<span> </span></div><div> task.addScriptableJavaObject("reportDataMap", reportData);</div><div> //set output options</div><div> HTMLRenderOption options = new HTMLRenderOption();</div><div> //set the image handler to a HTMLServerImageHandler if you plan on using the base image url.</div><div> options.setImageHandler(new HTMLServerImageHandler());</div><div> options.setOutputFormat(HTMLRenderOption.OUTPUT_FORMAT_PDF);</div><div> options.setOutputStream(response.getOutputStream());</div><div> options.setBaseImageURL(request.getContextPath()+"/images");</div><div> options.setImageDirectory(sc.getRealPath("/images"));</div><div> </div><div> task.setRenderOption(options);</div><div> </div><div> //run report</div><div> task.run();</div><div> task.close();</div><div> }catch (Exception e){</div><div> e.printStackTrace();</div><div> throw new ServletException( e );</div><div> } </div>
Find more posts tagged with
Comments
mwilliams
<p>Have you already been through the web viewer code to see how the export is handled there?</p>
easyleads
<p>Hi Michael,</p><p> </p><p>I tried to look into the viewer code but I'm kind of getting lost.</p><p>I found that upon export a script executes:</p><p> </p><p>birtEventDispatcher.broadcastEvent( birtEvent.__E_EXPORT_REPORT );</p><p> </p><p>How can I see the code that is executed?</p><p>Perhaps you can point me to an example of this basic implementation ?</p><p> </p><p>Thanks</p>