码迷,mamicode.com
首页 > Web开发 > 详细

js 实现打印功能

时间:2017-07-10 10:37:08      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:通过   test   width   pdfobject   实现   src   embed   obj   nbsp   

前端js实现打印功能的两种方式:

1、利用iframe,隐藏iframe,直接通过按钮直接打印,弹出打印设置页面。

    

<button onclick="doPrint();">print</button>
<iframe style="display:none"  id="printIframe" frameBorder=0 scrolling=no width="100%"  src="./test.pdf"></iframe>



function doPrint(){
        $("#printIframe")[0].contentWindow.print();
    }


此打印方法需要在服务中运行。

 

2、使用插件PDFObject.js

  

<script src="./js/PDFObject-new.js"></script>
<script type="text/javascript">

    window.onload = function (){
        var myPDF = new PDFObject({ url: "./test.pdf" }).embed();
      };
</script>

 

js 实现打印功能

标签:通过   test   width   pdfobject   实现   src   embed   obj   nbsp   

原文地址:http://www.cnblogs.com/java-chanjuan/p/7144124.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!