注意: 得引入Jquery.js包,客户端得安装Acrobat Reader DC.
IE 中用<embed id ="test1" src="1.pdf" type="application/pdf" width="600" heght="600" >
js print code:
let x = document.getElementById('test1');
x.print();
//提升性能加入下面方法,使用方式 excutePrint('DivId', 'embedId');
function excutePrint(divId, embedId) {
let oldElement = document.getElementById(divId);
let newWin = window.open();
if (newWin && newWin.document) {
let scrEl = newWin.document.createElement("script");
scrEl.setAttribute("src", "~/lib/jquery/dist/jquery.js");
newWin.document.head.appendChild(scrEl);
newWin.document.body.innerHTML = oldElement.innerHTML;
let newElement = newWin.document.getElementById(embedId);
setTimeout(function () {
newElement.print();
}, 1000)
}
}
chrome中用 <iframeid ="test1" src="1.pdf" width="600" heght="600" ></iframeid >
js print code:
let x = document.getElementById('test1');
try{
x.contentWindow.document.execCommand('print',false,null);
} catch(e){
x.contentWindow.print();
}