private void ZPLPrintLabels(string printerName, PrintLables[] labels, int height) { string labelIdCmd = string.Empty; string labelContentCmd = string.Empty; string headTitle = string.Empty; string barcodeNo = string.Empty; foreach (PrintLables label in labels) { labelIdCmd += "^FT" + label.XPos.ToString() + "," + label.YPos.ToString() + "^XG" + label.Id + ",1,1^FS"; if (label.Id == "HName") { //headTitle += "^FDMA," + label.Id + "^FS"; } if (label.Id == "ANo") { barcodeNo += "^FDMA,YF10069^FS"; } labelContentCmd += TextToHex(label.Text, label.Id, height); } #region 打印具有格式的小票 string content = labelContentCmd + "^XA^LH0,0^PR2,2^MD20^FO0,0" //+ headTitle + "^FO20,80^GB560,0,3^FS" + labelIdCmd + "^FT455,340^BQN,2,4" + barcodeNo + "^PQ1,0,1,Y^XZ"; PrintDiver.SendStringToPrinter(printerName, content); #endregion }
/// <summary> /// 二维码打印(半成品打印) /// </summary> /// <param name="l"></param> /// <param name="h"></param> /// <param name="cl"></param> /// <param name="str"></param> /// <returns></returns> public bool PrintQRCode(int l, int h, int cl, params string[] str) { if (str.Length < 5) { return(false); } l = l == 0 ? 80 : l; h = h == 0 ? 80 : h; cl = cl == 0 ? 360 : cl; StringBuilder sb = new StringBuilder(); sb.Append("^XA"); // 打印一个二维码:工单号码 sb.Append(string.Format("^LH{0},{1}^FO{2},{3}^BQ,2,{4}^FDQA,{5}^FS", l, h, 0, h, 0, str[0])); // 打印一列文字:str0[0] sb.Append(TextToHex(str[1], str[0], 30)); sb.Append(string.Format("^FT{0},{1}^XG{2},1,1^FS", 125 + l, h + 60, str[0])); sb.Append(TextToHex(str[2], str[0], 30)); sb.Append(string.Format("^FT{0},{1}^XG{2},1,1^FS", 125 + l, h + 90, str[0])); sb.Append(TextToHex(str[3], str[0], 30)); sb.Append(string.Format("^FT{0},{1}^XG{2},1,1^FS", 125 + l, h + 120, str[0])); sb.Append(TextToHex(str[4], str[0], 30)); sb.Append(string.Format("^FT{0},{1}^XG{2},1,1^FS", 125 + l, h + 150, str[0])); //sb.Append(string.Format("^LH{0},{1}^FO{2},{3}^BQ,2,{4}^FDQA,{5}^FS", l, h, 0 + cl, h, bch, str1[0])); //sb.Append(TextToHex(str1[1], str1[0], 24)); //sb.Append(string.Format("^FT{0},{1}^XG{2},1,1^FS", 125 + cl + l, h + 60, str1[0])); //sb.Append(TextToHex(str1[0], str1[0], 20)); //sb.Append(string.Format("^FT{0},{1}^XG{2},1,1^FS", 125 + cl + l, h + 90, str1[0])); sb.Append("^XZ"); return(PrintDiver.SendStringToPrinter(this.Name, sb.ToString())); }
/// <summary> /// 条码打印(标签两列) /// </summary> /// <param name="l">左边距 推荐值:0</param> /// <param name="h">上边距 推荐值:0</param> /// <param name="cl">第一列与第二列的距离 推荐值:0</param> /// <param name="bch">条码高 推荐值:0</param> /// <param name="str">条码内容1,内容2两个字符串 推荐值:11位字母数字组成</param> /// <returns>true /false 执行状态</returns> public bool PrintBarcode(int l, int h, int cl, int bch, params string[] str) { l = l == 0 ? 0 : l; h = h == 0 ? 8 : h; cl = cl == 0 ? 30 : cl; bch = bch == 0 ? 100 : bch; StringBuilder sb = new StringBuilder(); sb.Append("^XA"); //连续打印两列(单列只写一条) sb.Append(string.Format("^MD30^LH{0},{1}^FO{2},{3}^ACN,18,10^BY1.8,3,{4}^BC,,Y,N^FD{5}^FS", l, h, l, h, bch, str[0])); sb.Append(string.Format("^MD30^LH{0},{1}^FO{2},{3}^ACN,18,10^BY1.8,3,{4}^BC,,Y,N^FD{5}^FS", l, h, l + cl, h, bch, str[1])); sb.Append("^XZ"); return(PrintDiver.SendStringToPrinter(this.Name, sb.ToString())); }
private void ZPLPrintLabelsWithHexText(string printerName, PrintLables[] labels) { string labelIdCmd = string.Empty; string labelContentCmd = string.Empty; foreach (PrintLables label in labels) { labelIdCmd += "^FT" + label.XPos.ToString() + "," + label.YPos.ToString() + "^XG" + label.Id + ",1,1^FS"; labelContentCmd += label.Text; } string content = labelContentCmd + "^XA^LH0,0^PR2,2^MD20^FO0,0" + labelIdCmd + "^PQ1,0,1,Y^XZ"; PrintDiver.SendStringToPrinter(printerName, content); }
/// <summary> /// 打印一列文字 /// </summary> /// <param name="l">左边距</param> /// <param name="h">上边距</param> /// <param name="cl">行间距</param> /// <param name="bch"></param> /// <param name="str"></param> /// <returns></returns> public bool PrintText(int l, int h, int cl, params string[] str) { if (str.Length < 2) { return(false); } string[] str0 = str[0].Split(','); string[] str1 = str[1].Split(','); l = l == 0 ? 50 : l; h = h == 0 ? 80 : h; cl = cl == 0 ? 360 : cl; StringBuilder sb = new StringBuilder(); sb.Append("^XA"); // 打印一个二维码:str0[0] // sb.Append(string.Format("^LH{0},{1}^FO{2},{3}^BQ,2,{4}^FDQA,{5}^FS", l, h, 0, h, bch, str0[0])); // 打印一列文字:str0[0] sb.Append(TextToHex(str0[1], str0[0], 24)); sb.Append(string.Format("^FT{0},{1}^XG{2},1,1^FS", 125 + l, h + 60, str0[0])); sb.Append("^XZ"); return(PrintDiver.SendStringToPrinter(this.Name, sb.ToString())); }