IE 8 中 JS 调用 adobe reader 打印 PDF 文档

1. 下载 adobe reader 软件,并在 IE 浏览器中启用

    设置 -> 管理加载项 -> 启用 Adobe PDF Reader

    

2. Jsp 文件中 HTML 代码如下

<input type="button" value="打印(P)" onclick="directpdfprint('<%=imgPath_pdf %>')">
<div id="createPDFDIV" style="text-align:center;margin:0 auto;height:1px;width:1px" ></div>

3. 配置 JS 方法

<script type="text/javascript">
function directpdfprint(srcFile) {
    var pdfprint = document.getElementById("createPDF");
    if (pdfprint != undefined && pdfprint != null) {
        var parentNode = pdfprint.parentNode;
        parentNode.removeChild(pdfprint);
    }
    var pdfprintdiv = document.getElementById("createPDFDIV");
	
    var p = document.createElement("object");
    try {
        p.id = "createPDF";
        p.classid = "CLSID:CA8A9780-280D-11CF-A24D-444553540000";
        p.width = 1;
        p.height = 1;
        p.src = encodeURI(encodeURI(srcFile));// 处理中文名称
        pdfprintdiv.appendChild(p);
        //p.printWithDialog();// 带打印窗口的直接打印
        p.printAll();//直接打印
    } catch (e) {
    	alert("未安装adobe reader插件,请联系管理员安装!");  
    }
}
</script>

    

猜你喜欢

转载自blog.csdn.net/fujiang3673/article/details/80065862