<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)
{
//timeout
},
function(XFail){
//fail
document.getElementById("tipsmessage").innerHTML = "API可(kě)能未安裝或未啓動";
},
function(XSuccess){
//success
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';
}
}else{
if (apiResult.Message.length > 1)
document.getElementById("tipsmessage").innerHTML = apiResult.Message[0] + " : " + apiResult.Message[1];
else
document.getElementById("tipsmessage").innerHTML = apiResult.Message[0];
}
}
);
}
function GetSelfDraw(){
var selfdraw = {
"Text":
[
{
"Name" : "Text1" ,
"LabelType" : "1" ,
"X" : "9.525" ,
"Y" : "2.1167" ,
"Width" : "30.9562" ,
"Height" : "6.0854" ,
"Data" : "庫位編碼" ,
"IsBind" : "0" ,
"BindField" : "" ,
"FontName" : "黑(hēi)體(tǐ)" ,
"FontSize" : "9" ,
"FontStyle" : "1" ,
"RotateOrientation" : "0" ,
"HAlignment" : "1" ,
"VAlignment" : "1" ,
"ForeColor" : "Black" ,
"BackColor" : "Transparent" ,
"Visible" : "1"
},
{
"Name" : "Text3" ,
"LabelType" : "1" ,
"X" : "5.0271" ,
"Y" : "21.9604" ,
"Width" : "40.2167" ,
"Height" : "4.4979" ,
"Data" : "智高(gāo)軟件 服務智能制(zhì)造" ,
"IsBind" : "0" ,
"BindField" : "" ,
"FontName" : "黑(hēi)體(tǐ)" ,
"FontSize" : "7" ,
"FontStyle" : "1" ,
"RotateOrientation" : "0" ,
"HAlignment" : "1" ,
"VAlignment" : "1" ,
"ForeColor" : "Black" ,
"BackColor" : "Transparent" ,
"Visible" : "1"
}
],
"Barcode":
[
{
"Name" : "Barcode1" ,
"LabelType" : "1" ,
"X" : "8.7312" ,
"Y" : "9.525" ,
"Width" : "33.8667" ,
"Height" : "10.8479" ,
"Data" : "1234567890" ,
"IsBind" : "1" ,
"BindField" : "Field1" ,
"BarcodeType" : "code128" ,
"Code128CodeSet" : "3" ,
"CheckDigit" : "1" ,
"CheckDigitToText" : "1" ,
"Charset" : "3" ,
"FontName" : "Arial" ,
"FontSize" : "9" ,
"FontStyle" : "0" ,
"RotateOrientation" : "0" ,
"Alignment" : "0" ,
"CodeTextSpace" : "0" ,
"ShowText" : "1" ,
"ForeColor" : "Black" ,
"BackColor" : "Transparent" ,
"Visible" : "1"
}
],
"PageSettings":
{
"Width" : "52" ,
"Height" : "30" ,
"TopMargin" : "0" ,
"BottomMargin" : "0" ,
"LeftMargin" : "1" ,
"RightMargin" : "0" ,
"PrinterPaperAutoSet" : "1" ,
"UseQuickSetTool" : "1" ,
"Landscape" : "0"
},
"LabelDetail":
{
"Width" : "50" ,
"Height" : "30" ,
"RowSpan" : "2" ,
"ColumnSpan" : "2" ,
"Visible" : "1"
},
"DataBase":
{
"FieldNumbers" : "15" ,
"FieldNames":
[
]
}
};
return JSON.stringify(selfdraw);
}
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 = "3";
cfgData.SelfDraw = GetSelfDraw();
/*打印數(shù)據的類型,0-數(shù)組,1-Json數(shù)組,元素為(wèi)JSON對象,字段:值*/
cfgData.PrintDataType = 1;
/*傳遞打印數(shù)據 Json數(shù)組*/ /*內(nèi)容不允許 半角的逗号及半角的分隔符2315002468301572.jpg*/
var arr = [
{ Field1: '5002468301572'}, { Field1: '5002468301573'}
];
cfgData.PrintData = JSON.stringify(arr);
/*打印 發送給打印機進行(xíng)打印*/
CCPrintingAPI.Excute(cfgData,
XTimeout => { },
XFail => {
document.getElementById("tipsmessage").innerHTML = 'API可(kě)能未安裝或未啓動, ' + XFail;
},
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];
}
}
);
}