浏览器调用打印机

自定义打印页面内容:

<!-- 打印明细窗口 -->
<div id="divID">
    <div style="font-size: 12px;font-weight:normal; width:158px;margin-left:0px;margin-top:5px">
        <div style="padding-left: 5px;" id="proName">

        </div>
        <div style="padding-left: 5px;" id="proNo">

        </div>
        <div style="padding-left: 5px;" id="proGuar">

        </div>
        <div style="padding-left: 5px;" id="proAddr">

        </div>
        <div style="width:100%" id="proImg">

        </div>
    </div>
</div>

打印方法调用:

function printHtml(){
  var printHtml = "";
  printHtml = creatTB(list);
  window.document.body.innerHTML = printHtml; //需要打印的页面
  setTimeout(function () {
    window.print();
  }, 500);
}
//生成二维码打印内容
    function creatTB(data) {
        var printHtml = "";
        for (var i = 0; i < data.length; i++) {
            var htmlStr = basePath + '/QrCode/getImageCode?content=' + data[i].imgStr + '';
            $("#proName").text("品名:" + data[i].proName);
            $("#proNo").text("编号:" + data[i].qrcodeid);
            $("#proGuar").text("保质期:" + data[i].guarperd + "个月");
            $("#proAddr").text("产地:" + data[i].prodaddr);
            $("#proImg").html('<img style="display:block;width: 120Px;margin:10px auto " src="' + htmlStr + '" />');
            printHtml = printHtml + $("#divID").prop("outerHTML");
        }
        return printHtml;
    }

 

转载于:https://www.cnblogs.com/Singulariity-gs/p/10642682.html

    原文作者:weixin_30316097
    原文地址: https://blog.csdn.net/weixin_30316097/article/details/96026437
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞