1、首先使用LODOP这个web打印插件,需要进入LODOP官网http://www.lodop.net/demo.html下载install_lodop.exe安装
2、要引入下面这段代码:
<script type="text/javascript" language="javascript" src="LodopFuncs.js"></script>
<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></embed>
</object>
3、实现循环打印,我这个打印是在页面动态生成多个div,每次打印时只打印一个div里面的内容。
<script type="text/javascript">
var LODOP; // 声明为全局变量
// 打印操作
var timer, recCount, rownum;
function choosePrint() {
rownum = 0;
recCount = <%=list.size()%>;
showPrint(rownum);
timer = setInterval(printSave, "500");
}
function printSave() {
if (LODOP.PRINTA()) {
alert(000000);
if (rownum >= recCount) {
clearInterval(timer);
} else {
showPrint(rownum);
}
} else {
if (rownum >= recCount) {
clearInterval(timer);
} else {
showPrint(rownum);
}
}
}
function showPrint(id) {
Design1(id);
rownum++;
}
function Design1(id) {
CreatePrintPage(id);
LODOP.PREVIEW();
};
function CreatePrintPage(id) {
LODOP=getLodop(document.getElementById('LODOP_OB'),document.getElementById('LODOP_EM'));
LODOP.PRINT_INIT("打印控件功能演示_Lodop功能_分页输出二");
var strHTML="<table border='0' width='100%' >";
strHTML=strHTML+"<tr><td>";
strHTML=strHTML+document.getElementById("div"+id).innerHTML;
strHTML=strHTML+"</td></tr>";
LODOP.ADD_PRINT_TABLE(88,200,350,1,strHTML);
};
</script>
其中 <%=list.size()%>是需要打印数据的行数,即要在页面动态生成几个div。
<body>
<input type="button" id="btn" value="打印" width="20px;" height="60px;"
οnclick="choosePrint()">
<form id="printForm" name="printPrint"
action="/qrcode/qrcodepPrint.action">
<c:forEach var="qrCodeList" items="${qrCodeList }" varStatus="code">
<div class="div000" id="div${code.index}">
<table>
<tr>
<td width="50px;">物料${code.index}:</td>
<td><input style="border: 0px;" type="text" id="wuliao" name="wuliao"
value="${qrCodeList.wuliao}"></td>
</tr>
<tr>
<td colspan=2><textarea style="resize: none;border: 0px;" cols="35" id="remark" name="remark">${qrCodeList.remark}</textarea>
</td>
</tr>
</table>
<div>
<div>
<table>
<tr>
<td>
<table>
<tr>
<td>供应商:</td>
<td><input style="border: 0px;" type="text" id="suppler" name="suppler"
value="${qrCodeList.suppler}"></td>
</tr>
<tr>
<td>序号:</td>
<td><input style="border: 0px;" type="text" id="xuhao" name="xuhao"
value="${qrCodeList.xuhao}"></td>
<td></td>
</tr>
</table>
</td>
<td><img width="79" height="79"
src="<%=request.getContextPath()%>/qrcodes/${qrCodeList.imagePath}" />
</td>
</tr>
</table>
</div>
</div>
</div>
</c:forEach>
</form>
</body>