关于web页面直接进行打印的问题

本文介绍了如何在web前端页面实现直接打印内容,通过展示一个表格数据的打印示例,包括设置表格样式、填充数据以及调用打印插件的JS代码。用户在确认后,页面会使用LODOP插件预览并打印表格数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

很多时候我们需要直接在前台页面进行打印内容

 <div>
<form id="form1" >
<table   border="1" cellpadding="0";cellspacing="0" style="width:870px"" id="last">
<tr>
<th colspan ="12" style='font-size: 16px'>明细</th>
</tr>
<tr>
<td style='text-align: center;font-size: 12px;width:90px' id="qin_time"></td>
<td style='text-align: center;font-size: 12px;width:100px' id="qothers_name"></td>
<td style='text-align: center;font-size: 12px;width:50px' id="qothers_type"></td>
<td style='text-align: center;font-size: 12px;width:40px' id="qothers_count"></td>
<td style='text-align: center;font-size: 12px;width:40px' id="qothers_unit"></td>
<td style='text-align: center;font-size: 12px;width:40px' id="qothers_standard"></td>
<td style='text-align: center;font-size: 12px;width:40px' id="qothers_price"></td>
<td style='text-align: center;font-size: 12px;width:40px' id="qtotal_price"></td>
<td style='text-align: center;font-size: 12px;width:40px' id="qnototal_price"></td>
<td style='text-align: center;font-size: 12px;width:40px' id="qtax_rate"></td>
<td style='text-align: center;font-size: 12px;width:150px' id="qmanufacturer_name"></td>
<td style='text-align: center;font-size: 12px;width:90px' id="qstorage_name"></td>
<td style='text-align: center;font-size: 12px;width:60px' id="qpather"></td>
<td style='text-align: center;font-size: 12px;width:50px' id="qinput_person"></td>
</tr>
</table>
</form>
</div>


JS页面代码如下

var temp="";
var LODOP;
function CreateOneFormPage(){
LODOP=getLodop();  
var strBodyStyle="<style>table,td { border: 1 solid #000000;border-collapse:collapse }</style>";
var strFormHtml=strBodyStyle+"<body>"+document.getElementById("form1").innerHTML+"</body>";
LODOP.ADD_PRINT_HTM(15,15,700,700,strFormHtml);
myrefresh();
};
function myrefresh(){
   window.location.reload();
}


function prn1_preview() {
var current=new Date();
$("#qin_time").text("时间");
$("#qothers_name").text("物资名称");
$("#qothers_type").text("物资类别");
$("#qothers_count").text("数量");
$("#qothers_unit").text("单位");
$("#qothers_standard").text("规格型号");
$("#qothers_price").text("单价");
$("#qtotal_price").text("总价");
$("#qnototal_price").text("不含税价");
$("#qtax_rate").text("税额");
$("#qmanufacturer_name").text("供应商");
$("#qstorage_name").text("存放位置");
$("#qpather").text("送货人");
$("#qinput_person").text("录入人员");

var items = $("#other_rows").datagrid('getRows');
for(var i=0;i<items.length-1;i++){
temp+="<tr >";
temp+="<td style='text-align: center' >"+items[i].in_time+"</td>";
temp+="<td style='text-align: center'>"+items[i].others_name+"</td>";
temp+="<td style='text-align: center' >"+items[i].others_type+"</td>";
temp+="<td style='text-align: center'>"+items[i].others_count+"</td>";
temp+="<td style='text-align: center'>"+items[i].others_unit+"</td>";
temp+="<td style='text-align: center'>"+items[i].others_standard+"</td>";
temp+="<td style='text-align: center'>"+items[i].others_price+"</td>";
temp+="<td style='text-align: center'>"+items[i].total_price+"</td>";
temp+="<td style='text-align: center'>"+items[i].no_total_price+"</td>";
temp+="<td style='text-align: center'>"+items[i].tax_rate+"</td>";
temp+="<td style='text-align: center'>"+items[i].manufacturer_name+"</td>";
temp+="<td style='text-align: center'>"+items[i].storage_name+"</td>";
temp+="<td style='text-align: center'>"+items[i].pather+"</td>";
temp+="<td style='text-align: center'>"+items[i].input_person+"</td>";
temp+="</tr>";
}
$('#last').append(temp);

$.messager.confirm('Confirm','是否打印?',function(r){
   if (r){
    CreateOneFormPage();
    LODOP.PREVIEW();
   }
});

};


function print(){
prn1_preview();
}


这里面可能会用到插件,需要的可以联系我

<script type="text/javascript" src="<%=path%>/js/LodopFuncs.js"></script>



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值