使用jquery.qrcode 生成的二维码,使用window.print(); 无法实现打印

使用jquery.qrcode 生成的二维码,使用window.print(); 无法实现打印

代码如下

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>&nbsp;</title>
    <base href="${base}/">
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">

    <#include "/include/common.html"/>
    <script type="text/javascript" src="${base}/styles/js/jquery.qrcode.min.js"></script>
    <style type="text/css">
        .barcodeImg{margin:10px 0px}
    </style>

</head>

<body>

<!--startprint-->
<div style="margin:10px">
    <div id="bcTarget" class="barcodeImg"></div>
    <div id="qrcode" class="barcodeImg"></div>
</div>
<!--endprint-->

<input type="button" class="btn" value="打印" onclick="printQrcode();" />
</body>
</html>
<script type="text/javascript">
    $(function(){
        var sc = JSON.stringify(${printSmpleCodeStr});

        $("#bcTarget").empty().barcode(sc, "code128", {barWidth:1.5, barHeight:25,showHRI:true});
        jQuery('#qrcode').qrcode({width: 64,height: 64,text: sc});

//        var bdhtml = window.document.body.innerHTML;
//        var sprnstr = "<!--startprint-->";
//        var eprnstr = "<!--endprint-->";
//        var prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
//        prnhtml = prnhtml.substring(0,prnhtml.indexOf(eprnstr));
//        window.document.body.innerHTML=prnhtml;
//        window.print();
    });

    function printQrcode(){
        var bdhtml = window.document.body.innerHTML;
        var sprnstr = "<!--startprint-->";
        var eprnstr = "<!--endprint-->";
        var prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
        prnhtml = prnhtml.substring(0,prnhtml.indexOf(eprnstr));
        window.document.body.innerHTML=prnhtml;
        window.print();
    }
</script>

界面如下:
图片说明
点击打印按钮:
图片说明

预览时无法显示二维码,无法打印二维码。

你现在能打印了吗?我想请教一下,我也是这种方法,想打印,预览能显示二维码,但我想打印在小点的纸张上,请问怎么做?我在打印设置里设置过,但总是打不出来。