3. 打印
進行(xíng)相關參數(shù)設置後(指定打印機,設置模闆,設置打印數(shù)據),将指令通(tōng)過API傳給打印機。
#構建模闆
def GetSelfDrawTextBarcode():
vSelfdraw = CCSelfdraw()
#數(shù)據字段
FieldNames = { "Barcode", "Printdate" }
vSelfdraw.XDataBase.SetFieldNames(FieldNames)
vSelfdraw.XPageSettings.PrinterPaperAutoSet = 1
vSelfdraw.XPageSettings.UseQuickSetTool = 1
#标簽尺寸
vSelfdraw.XLabelDetail.Width = 70
vSelfdraw.XLabelDetail.Height = 50
vSelfdraw.XLabelDetail.ColumnSpan = 2
vSelfdraw.XLabelDetail.RowSpan = 2
#文本1
text1 = TextElement()
text1.LabelType = 1
text1.Name = "text1"
text1.X = 0
text1.Y = 3
text1.Width = 70
text1.Height = 8
text1.IsBind = 0
text1.BindField = ""
text1.Data = "庫位編碼"
text1.FontSize = 14
text1.FontName = "黑(hēi)體(tǐ)"
text1.HAlignment = 1
text1.VAlignment = 1
vSelfdraw.XTextElements.Add(text1)
#文本2
text2 = TextElement()
text2.LabelType = 1;
text2.Name = "text2";
text2.X = 0;
text2.Y = 38;
text2.Width = 70;
text2.Height = 8;
text2.IsBind = 1;
text2.BindField = "Printdate";
text2.Data = "";
text2.FontSize = 12;
text2.FontName = "黑(hēi)體(tǐ)";
text2.HAlignment = 1;
text2.VAlignment = 1;
vSelfdraw.XTextElements.Add(text2);
#條碼
barcode1 = BarcodeElement()
barcode1.LabelType = 1
barcode1.Name = "barcode1"
barcode1.X = 6
barcode1.Y = 15
barcode1.Width = 56
barcode1.Height = 20
barcode1.IsBind = 1
barcode1.BindField = "Barcode"
barcode1.Data = ""
barcode1.FontSize = 18
barcode1.FontName = "黑(hēi)體(tǐ)"
vSelfdraw.XBarcodeElements.Add(barcode1);
return vSelfdraw.ToString();
#打印回調
def print_callback(arg):
status = arg.Status
arg0 = arg.Message
sessionid = arg.SessionId
print("Excute Status: {:d}, SessionId:{:s}".format(status, sessionid))
if arg0 == None:
return
#打印成功
if status == 1 :
print("{:s}:{:s}".format(arg0[0],arg0[1]))
#打印
def printex(openid,token,printer,prtdata,ispreview,callback):
#構建模闆
selfdraw1 = GetSelfDrawTextBarcode()
cfgData = ConfigPrintSettings()
cfgData.XAction = "Print"
cfgData.XOpenId = openid
cfgData.XTokens = token
#cfgData.PrinterName = "Honeywell PC42t (203 dpi) - DP"
cfgData.PrinterName = printer
cfgData.Preview = ispreview;
#配置模闆 0本地模闆 1遠程模闆 2如本地不存在,使用遠程模闆,3不使用模闆 由代碼構建
cfgData.TemplateMode = 3
cfgData.SelfDraw = selfdraw1;
#傳入數(shù)據
#prtdata = "[{sku:'OBJ100001',name:'測試1',kw:'D12-1',bh:'RKD123451'},{sku:'OBJ100002',name:'測試2',kw:'D12-2',bh:'RKD123452'}]"
# prtdata = [{'sku':'OBJ100001','name':'測試1','kw':'D12-1','bh':'RKD123451'},{'sku':'OBJ100002','name':'測試2','kw':'D12-2','bh':'RKD123452'}]
#prtdata = ['OBJ100001;測試1;D12-1;RKD123451'] json.dumps(prtdata,ensure_ascii=False)
cfgData.PrintDataType = 1
cfgData.PrintData = prtdata;
CCPrintingApi.ExcuteEx(cfgData,callback)