直接打印PDF报告,而不是下载,打开和打印 [英] Print PDF report directly instead of downloading, opening and printing it

查看:214
本文介绍了直接打印PDF报告,而不是下载,打开和打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个JSF应用程序,它使用JasperReports在客户端计算机上的每个事务之后提供pdf文件作为下载。我按照教程。我们有什么方法可以直接打印它而不是下载它,因为最终用户必须打开它并给出打印命令。
(客户说有很多交易,他们想在独立的应用程序中以相同的方式打印收据,而不需要像打印对话框那样进行任何干预。)

I developed a JSF application which gives a pdf file as a download after each transaction at the client machine using JasperReports. I followed this tutorial. Is there any way we can directly print it rather than downloading it as the end user has to open it and give the print command. (Customers say that there are lot of transactions and they want to print the receipt in the same manner in a standalone application without any intervention like bringing the print dialog.)

推荐答案

如果没有出现打印对话框,您无法强制打印浏览器。

You cannot force the browser to print without a print dialog appearing.

但是,您可以设置内容 - 处理使浏览器在浏览器中打开可以打印的PDF。例如:

You can, however, set the Content-Disposition such that the browser opens up a PDF in the browser that can be printed. For example:

  /**
   * Sets the regular HTTP headers, regardless of whether this report is
   * embedded in the browser window, or causes a "Save As" dialog prompt to
   * download.
   */
  protected void setHeaders() {
    getServletResponse().setHeader( "Cache-Control", getCacheControl() );
  }

  /**
   * Sets the HTTP headers required to indicate to the browser that the
   * report is to be downloaded (rather than displayed in the current
   * window).
   */
  protected void setDownloadHeaders() {
    HttpServletResponse response = getServletResponse();
    response.setHeader( "Content-Description", getContentDescription() );
    response.setHeader( "Content-Disposition", "attachment, filename="
      + getFilename() );
    response.setHeader( "Content-Type", getContentType() );
    response.setHeader( "Content-Transfer-Encoding",
      getContentTransferEncoding() );
  }

这将提示用户保存PDF。如果更改Content-Disposition,浏览器将显示PDF内联而不提示保存。这将跳过必须打开PDF的步骤。

This will prompt the user to save the PDF. If you change the Content-Disposition, the browser will display the PDF inline without prompting to save. This will skip the step of having to open the PDF.

这篇关于直接打印PDF报告,而不是下载,打开和打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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