3. 打印
進行(xíng)相關參數(shù)設置後(指定打印機,設置模闆,設置打印數(shù)據),将指令通(tōng)過API傳給打印機。
#構建模闆
def GetSelfDraw():
vSelfdraw = CCSelfdraw()
#數(shù)據字段
FieldNames = { "ImageUrl" };
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;
#圖片設置
vImageElement = ImageElement()
vImageElement.Name = "Image1";
vImageElement.X = 0;
vImageElement.Y = 0;
vImageElement.Width = 70;
vImageElement.Height = 50;
vImageElement.IsBind = 1;
vImageElement.BindField = "ImageUrl";
vImageElement.KeepRatio = 1;
vImageElement.ImageColor = 2;
vSelfdraw.XImageElements.Add(vImageElement);
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 = GetSelfDraw()
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)