1

在我的应用程序中,我想打印驻留在 iframe 中的 PDF 文件。这是我的代码..

<iframe src="pdf/output.pdf" id="pdfFrame"></iframe>

这是打印pdf的脚本..

document.getElementById("pdfFrame").focus();
document.getElementById("pdfFrame").contentWindow.print();

上面的代码工作正常,但它会在打印之前打开一个窗口弹出窗口。但根据我的要求,我想要直接激光打印而不打开弹出窗口。

有没有办法做到这一点???

4

1 回答 1

0

The only way to bypass the print dialog is to tweak settings in IE and to write some VBScript.

See Bypass Printdialog in IE9

It only works in IE9, if you can change every client's ActiveX settings. Really should only be used in an intranet scenario where you control the clients.

<script language="VBScript">
    sub Print()
        OLECMDID_PRINT = 6
        OLECMDEXECOPT_DONTPROMPTUSER = 2
        OLECMDEXECOPT_PROMPTUSER = 1
        call WB.ExecWB(OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER,1)
    End Sub
    document.write "<object id='WB' width='0' height='0' classid='CLSID:8856F961-340A-11D0-A96B-00C04FD705A2'></object>"
</script>

<object id="WebBrowser1" width="0" height="0" classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"> </object>
<a href="#" onclick="Print()">Click Here to Print</a>
于 2013-04-19T16:16:03.107 回答