打印JasperReports客户端? [英] Print JasperReports client-side?

查看:96
本文介绍了打印JasperReports客户端?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个使用JasperReports的Web应用程序。我注意到报告是打印服务器端。

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

如何使报告打印在客户端(从Web浏览器)?

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

任何见解都会有所帮助。

Any insights will be helpful.

推荐答案

假设你有一个基于Servlet的架构:

Presuming you have a Servlets-based architecture:


  1. 使用 HttpServletResponse response =获取 HttpServletResponse 实例的句柄this.getThreadLocalResponse(); (例如)。

  2. 设置各种标题以指示文件附件。
  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" );


  • 配置 JRExporter (jre)以使用HttpServletRespone的输出流:

  • Configure the JRExporter (jre) to use the HttpServletRespone's output stream:

    
        jre.setParameter( JRExporterParameter.OUTPUT_STREAM, getOutputStream() );
    


  • 执行报告。

  • 浏览器将提示用户将报告另存为PDF文件。用户可以打印PDF。

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

    这篇关于打印JasperReports客户端?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆