静默打印嵌入的 PDF
我有一个网页,上面嵌入了 PDF。 我的代码如下所示:
<embed
type="application/pdf"
src="path_to_pdf_document.pdf"
id="pdfDocument"
width="100%"
height="100%">
</embed>
我有一个用于打印 PDF 的 javascript 代码:
function printDocument(documentId) {
//Wait until PDF is ready to print
if (typeof document.getElementById(documentId).print == 'undefined') {
setTimeout(function(){printDocument(documentId);}, 1000);
} else {
var x = document.getElementById(documentId);
x.print();
}
}
执行此代码时,Acrobat 插件会打开众所周知的打印对话框。 像这样的东西:
两个问题:
- 如何改进检测 PDF 已加载并准备打印的方法?
- 如何避免显示打印对话框?
有关我的系统的更多信息:
操作系统: Windows XP
浏览器: Internet Explorer 7
PDF 插件: Acrobat Reader 9
I have a web page with embedded PDF on it. My code looks like this:
<embed
type="application/pdf"
src="path_to_pdf_document.pdf"
id="pdfDocument"
width="100%"
height="100%">
</embed>
I have this javascript code for print my PDF:
function printDocument(documentId) {
//Wait until PDF is ready to print
if (typeof document.getElementById(documentId).print == 'undefined') {
setTimeout(function(){printDocument(documentId);}, 1000);
} else {
var x = document.getElementById(documentId);
x.print();
}
}
When this code is executed Acrobat plug-in opens the well-known print dialog. Something like this:
Two questions:
- How to improve the way to detect that PDF is loaded and ready for print?
- How to avoid showing print dialog?
A little more info about my system:
OS: Windows XP
Browser: Internet Explorer 7
PDF Plugin: Acrobat Reader 9
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您将无法使用普通的旧式 JavaScript 进行静默打印。 您希望您的打印机开始打印 100000000 页全黑页。 不是什么好事。 如果您想要静默打印并使其仅适用于 Internet Explorer,则可以使用 ActiveX 控件来实现此目的。 这需要对您的页面进行更高的安全设置,并让您的用户真正信任您的网站。
You are not going to be able to print silently with plain old JavaScript. How would you like your printer to start printing out 100000000 pages of all black. Not a good thing. If you want to print silently and have it work for Internet Explorer only, there are ActiveX controls out there that can do it. This requires higher security settings for your page and for your users to really trust your site.
这在受信任的 Intranet 环境中是可能的。
这将绕过打印对话框并直接发送到默认打印机。
This is possible in a trusted, Intranet environment.
This will bypass the print dialog and send directly to the default printer.
我想知道您是否真的需要在打印之前等待 - 打印作业不会为您处理这个问题吗? 我真心希望现代浏览器不会允许您(或任何与此相关的网站)在没有确认对话框的情况下进行打印(很久以前,一些旧浏览器曾经这样做过)。
I wonder if you actually need to wait before printing -- won't the print job handle that for you? And I truly hope no modern browser will allow you (or any website for that matter) to print without that confirmation dialog (some old browsers used to do that, a long time ago).
您可以通过更改
about:config
在 Firefox 中执行此操作。 添加print.always_print_silent
并将其设置为true
。You can do this in Firefox by changing
about:config
. Addprint.always_print_silent
and set it totrue
.