无需打开客户端打印机即可将 PDF 打印到客户端打印机
我正在开发一个用 Java 开发的 Web 应用程序,该应用程序在 Tomcat 上运行。我对 Web 应用程序有如下要求:
一个 JSP 页面包含一个 PDF 文件列表,每个文件都与一个复选框相关联。 JSP 页面有一个按钮。一旦用户通过选择关联的复选框选择了他想要打印的 PDF 文档,用户就可以单击该按钮。
然后,所有选定的 PDF 文档应发送到特定的本地打印机(即连接到用户访问 Web 应用程序的客户端计算机的打印机)。所选 PDF 文件不应在 acrobat reader 或浏览器中打开。 PDF 文档在发送到打印机时不应对用户可见。
有人可以帮我实现这个要求吗?
I am working on a web application developed in Java with struts running on Tomcat. I have a requirement in the web application as follows:
One JSP page having a list of PDF files each associated with a checkbox. The JSP page has one Button. Once the user selects the PDF documents he wants to print by selecting the associated checkboxes, user clicks on the button.
Then all the selected PDF docs should be sent to a specific local Printer( i.e. printer connected to the client machine where from user is accessing the web application). The selected PDF files should not be opened either in acrobat reader or in browser. The PDF docs should not be visible to the user while being sent to printer.
Could anyone please help me in implementing this requirement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可以通过 Internet Explorer 和 ActiveX 实现。使用 Google 搜索“自动打印”和“静音打印”。为此,您可能必须降低 Internet Explorer 中的安全设置。
我们在这里将它用于我们客户的一些内部网。
对于 Firefox,您可以通过 JavaScript 触发打印对话框。 (http://stackoverflow.com/questions/975652/silent-print-a-embedded-pdf)
如果是这种情况,您可以通过在
about:config
中设置print.always_print_silent=true
来禁用 FF 中的打印对话框。我从来没有自己做过,所以我不能确定它是否像 ActiveX 一样工作。
对于 Chrome,存在请求与 FF 相同的功能的问题。请参阅 https://code.google.com/p/chromium/issues/详情?id=31395。
It is possible with Internet Explorer and ActiveX. Search about "auto print" and "silent printing" with Google. You may have to lower security settings in Internet Explorer for that.
We're using it here for some Intranets from our Customers.
For Firefox you may be able to trigger the print dialog via javascript. (http://stackoverflow.com/questions/975652/silent-print-a-embedded-pdf)
If this is the case you can disable print dialog in FF with setting
print.always_print_silent=true
inabout:config
.Never did it on my own, so I cannot say for sure if it works like the ActiveX thing does.
For Chrome there is an issue requesting same feature like FF has. See https://code.google.com/p/chromium/issues/detail?id=31395.
为此,您很可能必须使用 Java Applet。浏览器没有打印 pdf 文档的固有功能。您也许能够访问“标准”adobe 插件,但据我所知,它并未暴露在标准脚本环境中。
您可以查看此处:Java Applet 可以使用打印机吗?
:建议对小程序进行签名,以防止安全限制和/或向用户提出烦人的问题以允许访问打印机。
您还需要在小程序中使用某种形式的 PDF 渲染器(以渲染到打印机)。类似于 http://java.net/projects/pdf-renderer/,了解更多这里: http://juixe.com/techknow/index.php/2008/01/17/print-a-pdf-document-in-java/
You will most likely have to use a Java Applet for this. The browser have no inherent capability to print a pdf document. You may be able to access the "standard" adobe plugin, but to my knowledge it is not exposed to the standard scripting environment.
You can look here: Can a Java Applet use the printer?
Note: it is recommended to have the applet signed to prevent security restrictions and/or annoying questions to the user to allow access to printer.
You'll also need some form of PDF renderer in your applet (to render to printer). Something like http://java.net/projects/pdf-renderer/, read more here: http://juixe.com/techknow/index.php/2008/01/17/print-a-pdf-document-in-java/
这对于 JavaScript 来说是不可能的。可以使用 Flash 或 Java 小程序。无论哪种情况,您都需要能够使用打印机驱动程序和自定义 PDF 阅读工具包。两者都有足够的插件用于 PDF 阅读,并且都带有打印 API。
如果我可以这么说,这是一个坏要求 - 强迫用户在不阅读文档的情况下打印文档是不好的 - 并且应该重新协商,特别是因为它非常简单无论如何,都可以将这些文档打印为 PDF。
That is not possible with JavaScript. It is possible with either Flash or a Java applet. In either case, you will need to be able to use both the Printer drivers and a custom PDF reading toolkit. There are adequate plugins for both for PDF reading, and both come with a printing API.
If I may say so, this is a bad requirement -- it is not good to force a user to print a document without reading it -- and should be re-negotiated, especially since it is trivially simple to have those documents print to PDF anyway.