用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>