3. 打印
進行(xíng)相關參數(shù)設置後(指定打印機,設置模闆,設置打印數(shù)據),将指令通(tōng)過API傳給打印機。
#構建模闆
def GetSelfDrawTextBarcodeDataMatrixQR():
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)
#文本3
text3 = TextElement()
text3.LabelType = 1
text3.Name = "text3"
text3.X = 0
text3.Y = 31
text3.Width = 70
text3.Height = 8
text3.IsBind = 1
text3.BindField = "Barcode"
text3.Data = ""
text3.FontSize = 15
text3.FontName = "Arial"
text3.FontStyle = 1
text3.HAlignment = 1
text3.VAlignment = 1
vSelfdraw.XTextElements.Add(text3)
#條碼1
barcode1 = BarcodeElement()
barcode1.LabelType = 1
barcode1.Name = "barcode1"
barcode1.X = 6
barcode1.Y = 15
barcode1.Width = 15
barcode1.Height = 15
barcode1.IsBind = 1
barcode1.BindField = "Barcode"
barcode1.Data = ""
barcode1.FontSize = 18
barcode1.FontName = "黑(hēi)體(tǐ)"
barcode1.BarcodeType = "datamatrix"
vSelfdraw.XBarcodeElements.Add(barcode1)
#條碼2
barcode2 = BarcodeElement()
barcode2.LabelType = 1
barcode2.Name = "barcode2"
barcode2.X = 40
barcode2.Y = 15
barcode2.Width = 15
barcode2.Height = 15
barcode2.IsBind = 1
barcode2.BindField = "Barcode"
barcode2.Data = ""
barcode2.FontSize = 18
barcode2.FontName = "黑(hēi)體(tǐ)"
barcode2.BarcodeType = "qr"
barcode2.RotateOrientation = 1
vSelfdraw.XBarcodeElements.Add(barcode2)
shape1 = ShapeElement()
shape1.Name = "shape1"
shape1.LabelType = 1
shape1.X = 1.5
shape1.Y = 1.5
shape1.Width = 66
shape1.Height = 46
shape1.ShapeType = 1
shape1.BoderWidth = 0.4
vSelfdraw.XShapeElements.Add(shape1)
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 = GetSelfDrawTextBarcodeDataMatrixQR()
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)