使用Lodop打印:
一、在官网下载http://www.lodop.net/download.html
若是安装还是提示未安装,就按转这个
二、准备两个js
三、需要在页面最上面加入
<html lang="zh" xmlns:th="http://www.thymeleaf.org"> <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0> <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0 pluginspage="install_lodop64.exe"></embed> </object> <meta charset="utf-8">
引入js
四、页面源码
<!DOCTYPE HTML> <html lang="zh" xmlns:th="http://www.thymeleaf.org"> <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0> <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0 pluginspage="install_lodop64.exe"></embed> </object> <meta charset="utf-8"> <head th:include="include :: header"></head> <link th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet" /> <link th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet" /> <script th:src="@{/js/jquery.min.js}"></script> <script th:src="@{/Lodop/LodopFuncs.js}"></script> <script th:src="@{/js/Mtils.js}"></script> <body class="white-bg"> <div class="btn-group-sm hidden-xs" style="margin-left: 20px" id="toolbar" role="group"> <a class="btn btn-success" onclick="PreviewMytable()" > <i class="fa fa-plus"></i> 打印 </a> </div> <div id="t1"> <table class="layui-table" border="1" cellpadding="0" cellspacing="0" align="center" style=" 700px; height:900px; cellspacing: 0;cellpadding:0"> <tr> <th colspan="7" style="text-align: center">试卷分析报告</th> </tr> <tr> <th colspan="7" style="text-align: center">[[${word.year}]]学年第[[${word.eduYear}==null?0:${word.eduYear}]]学期</th> </tr> <tr> <th style="text-align: center" colspan="2">课程名称:[[${word.lable}]]</th> <th style="text-align: center" colspan="2">班级:[[${word.deptName}]]</th> <th style="text-align: center" colspan="1">人数:[[${word.total}==null?0:${word.total}]]</th> <th style="text-align: center" colspan="2">日期:[[${word.time}]]</th> </tr> <tr style="text-align: center"> <td rowspan="5" colspan="1">试卷成绩</td> <td style="text-align: center">成绩等级</td> <td style="text-align: center">90-100</td> <td style="text-align: center">80-89</td> <td style="text-align: center">70-79</td> <td style="text-align: center">60-69</td> <td style="text-align: center"><60</td> </tr> <tr> <td style="text-align: center"></td> <td style="text-align: center">(优秀)</td> <td style="text-align: center">(良好)</td> <td style="text-align: center">(中等)</td> <td style="text-align: center">(及格)</td> <td style="text-align: center">(不及格)</td> </tr> <tr> <td style="text-align: center">人数</td> <td style="text-align: center">[[${word.best}==null?0:${word.best}]]人</td> <td style="text-align: center">[[${word.good}==null?0:${word.good}]]人</td> <td style="text-align: center">[[${word.medium}==null?0:${word.medium}]]人</td> <td style="text-align: center">[[${word.pass}==null?0:${word.pass}]]人</td> <td style="text-align: center">[[${word.fail}==null?0:${word.fail}]]人</td> </tr> <tr> <td style="text-align: center">所占比例</td> <td style="text-align: center">[[${word.bestRate}]]%</td> <td style="text-align: center">[[${word.goodRate}]]%</td> <td style="text-align: center">[[${word.mediumRate}]]%</td> <td style="text-align: center">[[${word.passRate}]]%</td> <td style="text-align: center">[[${word.failRate}]]%</td> </tr> <tr> <td style="text-align: center" colspan="3">平均成绩</td> <td style="text-align: center" colspan="3">[[${word.average}]]</td> </tr> <tr style=" height:200px;text-align: center"> <td>试卷情况分析</td> <td colspan="6"></td> </tr> <tr style=" height:200px;text-align: center"> <td >改进措施</td> <td colspan="6"></td> </tr> <tr> <td>教研室主任(签字):</td> <td colspan="3"></td> <td>系(部)主任(签字):</td> <td colspan="2"></td> </tr> </table> </div> </div> <div id="test1"> <template> <Table stripe :columns="columns1" :data="data1"></Table> </template> </div> <script type="text/javascript"> var LODOP; //声明为全局变量 function PreviewMytable() { var supplier = $("#supplierSpName").val(); var pcBillnr = $("#pcBillnr").val(); var creat = $("#creat").val(); var listSize = $("#listSize").val(); var rowHeight= (listSize * 7.0)+34.0; var rowHeight1= (listSize * 7.0)+40.0; var endWidth = (listSize * 7.0)+50.0; // if (LODOP.webskt && LODOP.webskt.readyState == 1) { LODOP = getLodop(document.getElementById('LODOP_OB'), document.getElementById('LODOP_EM')); LODOP.PRINT_INITA("-0.79mm","-3.7mm","210mm","220mm","试卷成绩分析"); //LODOP.PRINT_INITA(-3,-14,800,rowHeight,"进货单打印"); //设置纸张大小和格式 //LODOP.SET_PRINT_PAGESIZE(1,0,0,"A4"); /* LODOP.SET_PRINT_PAGESIZE(1,"220mm",endWidth+"mm",""); LODOP.SET_PRINT_STYLEA(0,"ItemType",2); LODOP.SET_PRINT_STYLEA(0,"ItemType",3); var strStyle="<style> .z1{font-size:13px}.z2{font-size:12px}td,th {border- 1px;border-style: solid;border-collapse: collapse}.wk{border-bottom:1px solid #fff;border-left: 1px solid #fff;border-right: 1px solid #fff;} </style>" //打印单抬头部分 */ /* LODOP.SET_PRINT_STYLEA(0,"FontSize",15); LODOP.SET_PRINT_STYLEA(0,"Bold",1); LODOP.SET_PRINT_STYLEA(0,"Alignment",3);*/ //引入打印内容 LODOP.ADD_PRINT_HTM("20.6mm","13.8mm","90%","100%",document.getElementById("t1").innerHTML); LODOP.NewPage(); //LODOP.ADD_PRINT_IMAGE(113,564,184,312,"<img border='0' src='vm.uploadList[0].imgUrl'width='100%' height='250'/>"); //LODOP.ADD_PRINT_IMAGE(113,564,184,312,"<img border='0' src='vm.uploadListe[0].imgUrl'width='100%' height='250'/>"); //LODOP.ADD_PRINT_HTM("20.6mm","13.8mm","90%","100%",document.getElementById("test1").innerHTML); /* LODOP.ADD_PRINT_IMAGE(39,210,400,400,"<img border='0' src='https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=d&word=%E7%99%BE%E5%BA%A6%E5%9B%BE%E7%89%87&step_word=&hs=0&pn=2&spn=0&di=147290&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&istype=2&ie=utf-8&oe=utf-8&in=&cl=2&lm=-1&st=-1&cs=2432587304%2C4134874795&os=3863472431%2C2265441716&simid=3485710891%2C47672788&adpicid=0&lpn=0&ln=1582&fr=&fmq=1543374993775_R&fm=detail&ic=0&s=undefined&hd=0&latest=0©right=0&se=&sme=&tab=0&width=&height=&face=undefined&ist=&jit=&cg=&bdtype=0&oriquery=&objurl=http%3A%2F%2Fphotocdn.sohu.com%2F20150908%2Fmp31043208_1441704680666_3.png&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3Bf5i7_z%26e3Bv54AzdH3FwAzdH3Fn8a9ndab_d808ac&gsm=0&rpstart=0&rpnum=0&islist=&querylist=&selected_tags=0' />"); */ //LODOP.ADD_PRINT_IMAGE(113,564,184,312,"<img border='0' src='http://43.226.38.125:8080/health/files/20161221100807932_20679.png'width='100%' height='250'/>"); //LODOP.ADD_PRINT_SETUP_BKIMG("data:image/jpg;base64, /9j/4AAQSkZJRgABAgIAAAAAAAD//gAeQUNEIFN5c3RlbXMgRGlnaXRhbCBJbWFnaW5nAP/AABEIAEIAYwMBIgACEQEDEQH/2wCEABQNDxEPDBQREBEWFRQXHjIgHhsbHj0rLiQySD9MS0c/RkRQWnNhUFVsVkRGZIhlbHZ6gIKATWCNl4x9lnN+gHsBHyEhLSctWDAwWLl7aXu5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5ubm5uf/EAHkAAQADAQEBAAAAAAAAAAAAAAADBAUCAQYQAAICAgAFAgQDBwUAAAAAAAECAAMEEQUSIUFREzEiYXGBFDJCBiORobHB0VNykuHwAQEBAQEAAAAAAAAAAAAAAAAAAgEDEQEBAQEBAAMAAAAAAAAAAAAAARECURIxQf/aAAwDAQACEQMRAD8A+yiIgInk4stCnQ+JvAgdyNr0H5dsflIbXA+K5wo7Azmu2qwlUYEjrrWjqB22RZ2RR9TImzLl/Sh+xnVhAEo5FoEC0vE9H46v+JlmnMotOg+m8N0mGOaw9JMMZiOsDeiZFGRdikBtvX4PuPpNSq1Lqw9bBlPeB1ERA9iJTycglvSrP+4j+kDu6/ZKVnr3bxM7OsxMWotbUjOfYa6mT3WrjUc5GyeijyZm24L3g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jJFClHs cIilmPYCfQcJ4NzMLL+oHYew/wAzSwODUYifEec9x7CaQAA0AAB2nO9eKwA0AANARESWsjjnDrrS MvDIF6jTIfZx/kTFTihqBXIRqbAO46b+s+ylPM4bj5Y+NdN5ExUz6rIpyj6QFbhlA10O5Dk5bkEG c5n7L2oS+HZyt5Q6mRdjcbxX1cllqeQm4lbefEt1pJMh/EcnXpvsJC5y2OjVdvwKyP7T2rhnEcht VYd5B7ldD+cvHPXVR2CxOyfcy9gcOvzrNVp8I92PsJocJ/ZmxCLM5wB/pod/xM+lqrSqsJWgVR7A CbevGYo4HB8bEAYqLLB+ojoPoJoT2JCiIiB5ERAREQEREBERAREQEREBERAREQP/2Q== "); /* for (var i=0;i<vm.uploadListe.length;i++) { console.log(vm.uploadListe[i].imgUrl) LODOP.ADD_PRINT_IMAGE(0,0,0,0,"<img border='0' src='vm.uploadListe[i].imgUrl'width='100%' height='250'/>"); }*/ /* for (var i=0;i<vm.uploadListe.length;i++) { var url = vm.uploadListe[i].imgUrl; console.log("vm.uploadListe[i].imgUrl"+i+":"+vm.uploadListe[i].imgUrl) LODOP.ADD_PRINT_IMAGE(113+(i*100),564,184,312,"<img border='0' src='url'width='100%' height='250'/>"); }*/ //LODOP.SET_PRINT_STYLEA(0,'HtmWaitMilSecs',3000) /* //直接打印 LODOP.PRINT(); //打印预览 LODOP.PREVIEW(); //打印维护 LODOP.PRINT_SETUP(); //打印设计 LODOP.PRINT_DESIGN(); */ /*LODOP.PRINT_DESIGN();*/ LODOP.PREVIEW(); /* } else { alert("LDOP還没准备好!"); } */ }; function print(){ if (needCLodop()) { window.On_CLodop_Opened = function() { PreviewMytable(); window.On_CLodop_Opened = null; }; } else window.onload = function() { PreviewMytable(); }; } </script> </body> </html>