首页 > Web开发 > 详细

打印html5中Canvas的方法

时间:2017-04-23 11:40:50      阅读:237      评论:0      收藏:0      [点我收藏+]
function print_voucher(){ // 打印的主要方法
    var win=window.open();
    win.document.write("<br><img src=‘"+canvas.toDataURL()+"‘/>");
    win.print();
    win.location.reload();
}

需要打开一个窗口进行打印,示例代码如下:

<script>
$(function(){

    var canvas=document.getElementById("canvas");
    var ctx=canvas.getContext("2d");

    ctx.fillStyle="gold";
    ctx.strokeStyle="blue";
    ctx.lineWidth=5;
    ctx.rect(50,50,100,100);
    ctx.fill();
    ctx.stroke();

    function print_voucher(){
        var win=window.open();
        win.document.write("<br><img src=‘"+canvas.toDataURL()+"‘/>");
        win.print();
        win.location.reload();
    }

    $("#printVoucher").click(function(){ print_voucher(); });


}); // end $(function(){});
</script>

<body>
    <canvas id="canvas" width=300 height=300></canvas><br>
    <button id="printVoucher">Print</button>
</body>

 

打印html5中Canvas的方法

原文:http://www.cnblogs.com/LLSutdy/p/6751886.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!