<script src="static/js/CCPrintingAPI.min.js"></script>
function GetPrinters(){
var cfgData = new Object;
cfgData .XAction = "Printers";
cfgData.XOpenId = m_OpenId;
cfgData.XTokens = m_Tokens;
CCPrintingAPI.Excute(cfgData ,
function(XTimeout){ },
function(XFail){
document.getElementById("tipsmessage").innerHTML = "API可(kě)能未安裝或未啓動";
},
function(XSuccess){
var apiResult = JSON.parse(XSuccess.trim());
if(apiResult.Status=="1"){
/*獲取到打印機列表*/
var prts = document.getElementById("Printers");
prts.length = 0;
if(apiResult.Message.length > 1 ){
for(var i = 1 ;i < apiResult.Message.length;i++){
prts.options.add(new Option(apiResult.Message[i],apiResult.Message[i]));
}
/*設置上(shàng)次使用的打印機*/
prts.options[0].selected = 'selected';
}
}
}
);
}
function Print() {
var prts = document.getElementById("Printers");
var selPrinter = prts.options[prts.selectedIndex].text;
var cfgData = new Object;
cfgData.XAction = "Print"
cfgData.XOpenId = m_OpenId;
cfgData.XTokens = m_Tokens;
/*指定打印機*/
cfgData.PrinterName =selPrinter ;
/*模闆方式,0-客戶端模闆,1-遠程模闆,
2-如果本地模闆存在,使用本地,不存在使用遠程模闆,3-不使用模闆*/
cfgData.TemplateMode = "1";
/*遠程模闆URL或本地模闆的文件夾*/
cfgData.TemplateURL = "http://img.51321.cn/web/chicore/VPrinting/API";
//cfgData.TemplateURL = "E:\\臨時(shí)數(shù)據\\打印\\打印樣本\\API标簽模闆";
/*模闆文件名*/
cfgData.TemplateName = "183601-70X40.Lblx";
/*打印數(shù)據的類型,0-數(shù)組,1-Json數(shù)組,元素為(wèi)JSON對象,字段:值*/
cfgData.PrintDataType = 1;
/*傳遞打印數(shù)據 Json數(shù)組*/ /*內(nèi)容不允許 半角的逗号及半角的分隔符*/
var arr = [
{ sku: 'OBJ100001', name: '測試1', kw: 'D12-1', bh: 'RKD123451' },
{ sku: 'OBJ100002', name: '測試2', kw: 'D12-2', bh: 'RKD123452' },
{ sku: 'OBJ100003', name: '測試3', kw: 'D12-3', bh: 'RKD123453' },
];
cfgData.PrintData = JSON.stringify(arr);
/*打印 發送給打印機進行(xíng)打印*/
CCPrintingAPI.Excute(cfgData,
function (XTimeout) { },
function (XFail) {
document.getElementById("tipsmessage").innerHTML = "API可(kě)能未安裝或未啓動";
},
function (XSuccess) {
var apiResult = JSON.parse(XSuccess.trim());
if (apiResult.Status == "1") {
document.getElementById("tipsmessage").innerHTML = apiResult.Message[0] + apiResult.Message[1];
}
}
);
}