用cnftPrint做了个web打印小票的代码,感觉上手好简单

原文: 用cnftPrint做了个web打印小票的代码,感觉上手好简单

用cnftPrint官方的例子改了一下,做了个web打印小票的代码,感觉上手好简单,几句代码搞定,简洁的不行了。

重点就是两个参数:strPrintFormat(打印格式),strPrintValue(打印数据),

然后POST给本地服务就行了。

以下是代码:

<!DOCTYPE html>
<html>
<head>
<title>小票打印</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

var strPrintFormat="";
//参数:纸张宽度(毫米),纸张上、下、左、右边预留空白宽度(毫米),每行之间空白分隔的高度(毫米)
strPrintFormat+="Paper,74.0,10.0,10.0,5.0,5.0,5.0";


var strPrintValue="";
//参数:字体名称,字体大小,字体颜色,字体背景颜色,字体样式,打印文本
strPrintValue+="宋体,14,000000,FFFFFF,0,某某公司收费凭条";
strPrintValue+="|宋体,12,000000,FFFFFF,0,缴费项目:某某公司费用";
strPrintValue+="|宋体,12,000000,FFFFFF,0,缴费号码:88888888";
strPrintValue+="|宋体,12,000000,FFFFFF,0,缴费金额:68.00";
strPrintValue+="|宋体,12,000000,FFFFFF,0,大写金额:陆拾捌元";
strPrintValue+="|宋体,12,000000,FFFFFF,0,客户名称:张三";
strPrintValue+="|宋体,12,000000,FFFFFF,0,客户地址:四川省成都市光华大道";
strPrintValue+="|宋体,12,000000,FFFFFF,0,交易时间:2019-12-12 10:21:37";
strPrintValue+="|宋体,12,000000,FFFFFF,0,交易流水:9fa3a177-54a7-4fe2-a6bb-fb347d4a98ac";
strPrintValue+="|宋体,12,000000,FFFFFF,0,操作人员:李四";
strPrintValue+="|宋体,12,000000,FFFFFF,0,操作分店:光华分店";


//提交打印数据,并立即向默认打印机打印
//飞天Web打印助手:http://www.cnft.cn
$("#btnRun").click(function(){
$.post("http://localhost:8918/cnftPrintTicket",
{
PrintFormat:strPrintFormat,
PrintValue:strPrintValue
},
function(strResult){
$("#txtResult").val("返回值:" + strResult);
});
});

});
</script>
</head>
<body>
<input id="txtResult" type="text" value="" />
<button id="btnRun" type="button">运行</button>

</body>
</html>

猜你喜欢

转载自www.cnblogs.com/lonelyxmas/p/12104785.html