1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 在web页面打开pdf文件并打印

在web页面打开pdf文件并打印

时间:2021-03-07 02:34:56

相关推荐

在web页面打开pdf文件并打印

需求:用户在前段页面点击打印按钮,打开pdf文件并打印,这样可以减少用户的操作次数,增强用户体验性。

思路:用iframe标签加载pdf再打印

1.js动态加载iframe标签:

2.兼容IE浏览器

<script type="text/javascript">

$(document).ready(function(){

var str = '<iframe style="display:none" id="printIframe" src="http://localhost:7613/PC/ReportFile/PDFFile/CommdityOrderList.pdf"></iframe>';

$('body').append(str);

//判断是否IE浏览器

if (!!window.ActiveXObject || "ActiveXObject" in window) {

window.frames['printIframe'].focus();

print();

}

else {

document.getElementById('printIframe').focus();

document.getElementById('printIframe').contentWindow.print();

}

});

</script>

最终效果:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。