当我单击 print.gif 按钮时,我需要打印 .pdf 文件(我使用 jasperReport 生成它并将其保存在服务器上)。 现在我发现这个解决方案适用于 Firefox,但不适用于 IE!
function printPdf(){
var url= document.getElementById('_url').value;
newwindow=window.open();
newdocument=newwindow.document;
newdocument.write('<embed type="application/pdf" src="'+url+'"
id="pdfDocument" height="100%" width="100%" ></embed> <SCR'+'IPT
LANGUAGE="JavaScript">window.print();window.close();</SCR'+'IPT>');
}
我也尝试了 document.close();
window.focus();
window.print();
window. close();
,但它们不起作用!
我阅读了很多主题,但找不到该问题的解决方案!
最佳答案
在 html 中创建一个 iframe
:
<iframe id="pdf-iframe">
然后更改该 iframe
的 src
和加载时
,打印它。
$('#pdf-iframe').attr("src", pdf_url).load(function(){
document.getElementById('pdf-iframe').contentWindow.print();
});
关于javascript - 使用 javascript 或 jquery 打印 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16400508/