打印功能

来源:互联网 发布:windows系统启动 efi 编辑:程序博客网 时间:2024/05/10 20:27

在web中开发打印功能

截图1 


截图2



代码

      /*截图打印统计饼状图*/      document.querySelector(".countImagePrint").onclick = function(){          html2canvas(document.getElementById("alarmCountContent"), {//截图              allowTaint : true,              taintTest : false,              onrendered : function(canvas) {               //生成base64图片数据               var dataUrl = canvas.toDataURL();               var newImg = document.createElement("img");               newImg.src = dataUrl;                         //利用iframe保存打印区域,避免影响原document的bodyvar iframe = document.createElement('iframe');var doc = null;iframe.setAttribute('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');document.body.appendChild(iframe);doc = iframe.contentWindow.document;//写入需打印的内容    doc.write('<img src="'+newImg.src+'" />');doc.close();iframe.contentWindow.focus();iframe.contentWindow.print();if (navigator.userAgent.indexOf("MSIE") > 0) {     document.body.removeChild(iframe);  }           }          });             }


0 0