分页打印标识符号
前置打印的时候下一页
<style>
* {
padding: 0px;
margin: 0px;
}
</style>
<script src="jquery.min.js"></script>
<script src="template.js"></script>
<script src="jquery.qrcode.min.js"></script>
<script type="text/javascript">
function createPrint() {
var list = eval('(' + $.trim($("#dbContent").val()) + ')');
var html = template('tpl', { data: list });
$("#main").append(html);
$("#divData").remove();
$(".qrcode").each(function () {
$(this).qrcode({
//render: "table", //table方式
width: 90, //宽度
height: 90, //高度
text:$(this).attr("data-id") //任意内容
});
});
var canvas = $('.qrcode canvas')
var img = canvas[0].toDataURL("image/png")
$('.qrcode').html("<img src='" + img + "'>")
//setTimeout(function () {
// $(".qrcode").each(function () {
// $(this).find("table").css("margin", "0px auto");
// });
//},1000);
}
function cpint() {
bdhtml = window.document.body.innerHTML;
sprnstr = "<!--startprint-->";
eprnstr = "<!--endprint-->";
prnhtml = bdhtml.substr(bdhtml.indexOf(sprnstr) + 17);
prnhtml = prnhtml.substring(0, prnhtml.indexOf(eprnstr));
window.document.body.innerHTML = prnhtml;
window.print();
}
</script>
<div id="divData" style="width:100%;">
<button type="button" οnclick="createPrint();" style="height:50px;">生成打印数据,必须为以下格式,必须是偶数</button>
<textarea id="dbContent" rows="20" style="width:90%;">
[
{
"KHMC": "胜利采油厂",
"BY5": null,
"WHR": "wxazbhsy",
"CARDID": "92b715f7b3c04e839af5db0c5e26b829",
"BY4": null,
"BY3": null,
"BY2": null,
"BY1": "2018050001",
"PKID": "7fda66cff1ff4073adff50874190cbc3",
"WHSJ": "2018-05-03 15:04:21",
"BZ": null,
"ISUSE": "0"
}, {
"KHMC": "胜利采油厂",
"BY5": null,
"WHR": "wxazbhsy",
"CARDID": "92b715f7b3c04e839af5db0c5e26b828",
"BY4": null,
"BY3": null,
"BY2": null,
"BY1": "2018050002",
"PKID": "bd2d1a01e78c445d88e6619844b275ba",
"WHSJ": "2018-05-03 15:04:21",
"BZ": null,
"ISUSE": "0"
}]
</textarea>
</div>
<button type="button" οnclick="cpint();" style="height:50px;">打印</button>
<!--startprint--><!--注意要加上html里star和end的这两个标记-->
<table style="width:100%;" id="main"></table>
<!--endprint-->
<script id="tpl" type="text/html">
<%for (var i=0;i < data.length; i++) {%>
<tr>
<td style="text-align:center;">
<div style="height:5px;"></div>
<div style="width:90%;text-align:center;border:solid 2px black; margin:0px auto;">
<p style="font-weight:bold;font-size:14px;margin-top:8px;">胜利通海油服福通公司(制氧厂)</p>
<p style="font-weight: bold; font-size: 15px; margin-top: 5px;">乙炔票(壹瓶)- 海洋</p>
<div style="height:5px;"></div>
<div style="float: left; width: 10%;">
<p style="width:20px;margin:0px auto;font-weight:bold;font-size:13px;">乙炔气体</p>
</div>
<div style="float:left;width:80%;">
<div class="qrcode" data-id="<%=data[i].CARDID%>" style="text-align:center;"></div>
</div>
<div style="float:left;width:10%;">
<p style="width: 20px; margin: 0px auto; font-weight: bold; font-size: 13px;">严禁烟火</p>
</div>
<div style="clear:both;"></div>
<p style="font-size: 12px; margin-top: 5px;">联系电话:8577307 8577308 2018-4-4前有效</p>
<div style="height:8px;"></div>
</div>
<div style="height:5px;"></div>
</td>
<td style="text-align:center;">
<div style="height:5px;"></div>
<div style="width:90%;text-align:center;border:solid 2px black; margin:0px auto;">
<p style="font-weight:bold;font-size:14px;margin-top:8px;">胜利通海油服福通公司(制氧厂)</p>
<p style="font-weight: bold; font-size: 15px; margin-top: 5px;">乙炔票(壹瓶)- 海洋</p>
<div style="height:5px;"></div>
<div style="float: left; width: 10%;">
<p style="width:20px;margin:0px auto;font-weight:bold;font-size:13px;">乙炔气体</p>
</div>
<div style="float:left;width:80%;">
<div class="qrcode" data-id="<%=data[i+1].CARDID%>" style="text-align:center;"></div>
</div>
<div style="float:left;width:10%;">
<p style="width: 20px; margin: 0px auto; font-weight: bold; font-size: 13px;">严禁烟火</p>
</div>
<div style="clear:both;"></div>
<p style="font-size: 12px; margin-top: 5px;">联系电话:8577307 8577308 2018-4-4前有效</p>
<div style="height:8px;"></div>
</div>
<div style="height:5px;"></div>
</td>
</tr>
<% i++; }%>
</script>
++分页打印
<%
List list = (List) request.getAttribute("list");
for (int i=0;i<list.size();i++) {
Map map1 = (Map)list.get(i);
Map map2 = null;
if(i+1<=list.size()-1)
{
map2 = (Map)list.get(i+1);
}
%>
<% if((i+1)%10==1){ %>
<table style="width:100%;page-break-before:always" id="main">
<%} %>
<tr>
<td style="text-align:center;">
<div style="height:5px;"></div>
<div style="width:90%;text-align:center;border:solid 2px black; margin:0px auto;">
<p style="font-weight:bold;font-size:14px;margin-top:8px;">胜利通海福通公司制氧厂</p>
<p style="font-weight: bold; font-size: 15px; margin-top: 5px;"><%=map1.get("LX") %>(壹瓶)-<%=map1.get("KHMC")%>-<%=map1.get("BY1") %></p>
<div style="height:5px;"></div>
<div style="float: left; width: 10%;">
<p style="width:20px;margin:0px auto;font-weight:bold;font-size:13px;">
<%=map1.get("LX") %>
</p>
</div>
<div style="float:left;width:80%;">
<div class="qrcode" data-id="<%=map1.get("PKID")%>" style="text-align:center;"></div>
</div>
<div style="float:left;width:10%;">
<p style="width: 20px; margin: 0px auto; font-weight: bold; font-size: 13px;">严禁烟火</p>
</div>
<div style="clear:both;"></div>
<p style="font-size: 12px; margin-top: 5px;">联系电话:8577307 8577308 <%=map1.get("BY2")%>前有效</p>
<div style="height:8px;"></div>
</div>
<div style="height:5px;"></div>
</td>
<td style="text-align:center;">
<div style="height:5px;"></div>
<% if(map2!=null){ %>
<div style="width:90%;text-align:center;border:solid 2px black; margin:0px auto;">
<p style="font-weight:bold;font-size:14px;margin-top:8px;">胜利通海福通公司制氧厂</p>
<p style="font-weight: bold; font-size: 15px; margin-top: 5px;"><%=map2.get("LX") %>(壹瓶)-<%=map2.get("KHMC")%>-<%=map2.get("BY1") %></p>
<div style="height:5px;"></div>
<div style="float: left; width: 10%;">
<p style="width:20px;margin:0px auto;font-weight:bold;font-size:13px;">
<%=map2.get("LX") %>
</p>
</div>
<div style="float:left;width:80%;">
<div class="qrcode" data-id="<%=map2.get("PKID")%>" style="text-align:center;"></div>
</div>
<div style="float:left;width:10%;">
<p style="width: 20px; margin: 0px auto; font-weight: bold; font-size: 13px;">严禁烟火</p>
</div>
<div style="clear:both;"></div>
<p style="font-size: 12px; margin-top: 5px;">联系电话:8577307 8577308 <%=map1.get("BY2")%>前有效</p>
<div style="height:8px;"></div>
</div>
<%}else{ %>
<%} %>
<div style="height:5px;"></div>
</td>
</tr>
<% i++;%>
<% if((i+1)%10==0 || i==list.size()){ %>
</table>
<%} %>
<% }%>