3. 打印
進行(xíng)相關參數(shù)設置後(指定打印機,設置模闆,設置打印數(shù)據),将指令通(tōng)過API傳給打印機。
function Print() {
var prts = document.getElementById("Printers");
var selPrinter = prts.options[prts.selectedIndex].text;
var cfgPrintSettings = new Object;
cfgPrintSettings.XAction = "Print"
var ccdriverPrinter = new Object;
/*免驅打印機名稱ChicoreDriver-USB-*/
ccdriverPrinter.Name = selPrinter ;
ccdriverPrinter.InterfaceType = 0;
/*打印方向 0-0°,1-90°,2-180°,3-270°*/
ccdriverPrinter.Direction = 0;
/*打印濃度0~10*/
ccdriverPrinter.Density = 5;
/*打印方式 0-熱轉印,1-熱敏*/
ccdriverPrinter.MediaType = 1;
/*介質類型 0-連續紙,2-有(yǒu)間(jiān)隙的标簽,3-有(yǒu)标記的紙*/
ccdriverPrinter.MediaSensing = 0;
/*負片打印 0-否,2-是*/
ccdriverPrinter.ReversePrint= 0;
/*水(shuǐ)平偏移mm*/
ccdriverPrinter.StartX= 0;
/*垂直偏移mm*/
ccdriverPrinter.StartY= 0;
/*指定打印機*/
cfgPrintSettings.PrinterName =JSON.stringify(ccdriverPrinter);
/*模闆方式,0-客戶端模闆,1-遠程模闆,
2-如果本地模闆存在,使用本地,不存在使用遠程模闆,3-不使用模闆*/
cfgPrintSettings.TemplateMode = "1";
/*遠程模闆URL或本地模闆的文件夾*/
cfgPrintSettings.TemplateURL = "http://img.51321.cn/web/chicore/VPrinting/API";
//cfgPrintSettings.TemplateURL = "E:\\臨時(shí)數(shù)據\\打印\\打印樣本\\API标簽模闆";
/*模闆文件名*/
cfgPrintSettings.TemplateName = "985.Lblx";
/*打印數(shù)據的類型,0-數(shù)組,1-Json數(shù)組,元素為(wèi)JSON對象,字段:值*/
cfgPrintSettings.PrintDataType = 1;
/*傳遞打印數(shù)據 Json數(shù)組*/ /*內(nèi)容不允許 半角的逗号及半角的分隔符*/
var arr =[
{"Field1":"吉祥如意餐廳","Field2":"1002104190264","Field3":"2021.04.19 12:20:55","Field4":"0107610/香爆脆羊肉串","Field5":"1.00","Field6":"1.00","Field7":"1.00","Field8":"5.28","Field9":"7.00","Field10":"16.20","Field11":"100.00","Field12":"83.80","Field13":"感謝您的光臨,歡迎下次再來(lái)","Field14":"http://51321.cn","Field15":"支付寶","Field16":"找零:","Field17":""},
{"Field1":"吉祥如意餐廳","Field2":"1002104190264","Field3":"2021.04.19 12:20:55","Field4":"0107611/德州扒雞","Field5":"62.00","Field6":"1.00","Field7":"62.00","Field8":"5.28","Field9":"7.00","Field10":"16.20","Field11":"100.00","Field12":"83.80","Field13":"感謝您的光臨,歡迎下次再來(lái)","Field14":"http://51321.cn","Field15":"支付寶","Field16":"找零:","Field17":""},
{"Field1":"吉祥如意餐廳","Field2":"1002104190264","Field3":"2021.04.19 12:20:55","Field4":"0107612/北京片皮烤鴨","Field5":"158.00","Field6":"1.00","Field7":"158.00","Field8":"5.28","Field9":"7.00","Field10":"16.20","Field11":"100.00","Field12":"83.80","Field13":"感謝您的光臨,歡迎下次再來(lái)","Field14":"http://51321.cn","Field15":"支付寶","Field16":"找零:","Field17":""}
];
cfgPrintSettings.PrintData = JSON.stringify(arr);
/*是否啓用即打即停,0-否,1-是*/
cfgPrintSettings.PrintToStop = "1";
/*打印 發送給打印機進行(xíng)打印*/
CCPrintingAPI.Excute(cfgPrintSettings,
function (XTimeout) { },
function (XFail) {
document.getElementById("tipsmessage").innerHTML = "API可(kě)能未安裝或未啓動";
},
function (XSuccess) {
var apiResult = JSON.parse(XSuccess.trim());
if (apiResult.Status == "1") {
var smsg = apiResult.Message[0];
if(apiResult.Message.length > 1)
smsg += " : " + apiResult.Message[1]
document.getElementById("tipsmessage").innerHTML = smsg;
}else{
if (apiResult.Message.length > 1)
document.getElementById("tipsmessage").innerHTML = apiResult.Message[0] + " : " + apiResult.Message[1];
else
document.getElementById("tipsmessage").innerHTML = apiResult.Message[0];
}
}
);
}