Print JasperReports client-side?

佐手、 提交于 2020-01-09 08:03:07

问题


I have developed a web application that uses JasperReports. I noticed that the reports are printing server-side.

How do you make the reports print client-side (from the web browser)?

Any insights will be helpful.


回答1:


Presuming you have a Servlets-based architecture:

  1. Get a handle on the HttpServletResponse instance with HttpServletResponse response = this.getThreadLocalResponse(); (for instance).
  2. Set the various headers to indicate a file attachment.
    HttpServletResponse response = getServletResponse();
    response.setHeader( "Content-Description", "File Transfer" );
    response.setHeader( "Content-Disposition", "attachment; filename=" +
      "report.pdf" );
    response.setHeader( "Content-Type", "application/pdf" );
    response.setHeader( "Content-Transfer-Encoding", "binary" );
    
  3. Configure the JRExporter (jre) to use the HttpServletRespone's output stream:
        jre.setParameter( JRExporterParameter.OUTPUT_STREAM, getOutputStream() );
    
  4. Execute the report.

The browser will prompt the user to save the report as a PDF file. The user can print the PDF.



来源:https://stackoverflow.com/questions/4694737/print-jasperreports-client-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!