3. 打印
進(jìn)行相關(guān)參數(shù)設(shè)置后(指定打印機(jī),設(shè)置模板,設(shè)置打印數(shù)據(jù)),將指令通過API傳給打印機(jī)。
#構(gòu)建模板
def GetSelfDrawTextBarcode():
vSelfdraw = CCSelfdraw()
#數(shù)據(jù)字段
FieldNames = { "Barcode", "Printdate" }
vSelfdraw.XDataBase.SetFieldNames(FieldNames)
vSelfdraw.XPageSettings.PrinterPaperAutoSet = 1
vSelfdraw.XPageSettings.UseQuickSetTool = 1
#標(biāo)簽尺寸
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 = "黑體"
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 = "黑體";
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 = "黑體"
vSelfdraw.XBarcodeElements.Add(barcode1);
return vSelfdraw.ToString();
#打印回調(diào)
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):
#構(gòu)建模板
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遠(yuǎn)程模板 2如本地不存在,使用遠(yuǎn)程模板,3不使用模板 由代碼構(gòu)建
cfgData.TemplateMode = 3
cfgData.SelfDraw = selfdraw1;
#傳入數(shù)據(jù)
#prtdata = "[{sku:'OBJ100001',name:'測(cè)試1',kw:'D12-1',bh:'RKD123451'},{sku:'OBJ100002',name:'測(cè)試2',kw:'D12-2',bh:'RKD123452'}]"
# prtdata = [{'sku':'OBJ100001','name':'測(cè)試1','kw':'D12-1','bh':'RKD123451'},{'sku':'OBJ100002','name':'測(cè)試2','kw':'D12-2','bh':'RKD123452'}]
#prtdata = ['OBJ100001;測(cè)試1;D12-1;RKD123451'] json.dumps(prtdata,ensure_ascii=False)
cfgData.PrintDataType = 1
cfgData.PrintData = prtdata;
CCPrintingApi.ExcuteEx(cfgData,callback)