Exemplo n.º 1
0
        /// <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(RawPrinterHelper.SendStringToPrinter(this.Name, sb.ToString()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 打印标签
        /// </summary>
        /// <param name="printerName"></param>
        /// <param name="labels"></param>
        /// <param name="height"></param>
        private void ZPLPrintLabels(string printerName, Label[] labels, int height)
        {
            string labelIdCmd      = string.Empty;
            string labelContentCmd = string.Empty;
            string headTitle       = string.Empty;
            string barcodeNo       = string.Empty;

            foreach (Label 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,YF786607834865^FS";
                }
                if (label.Id == "MResponsible")
                {
                    labelContentCmd += TextToHex(label.Text, label.Id, 30);
                }
                else if (label.Id == "BDate")
                {
                    labelContentCmd += TextToHex(label.Text, label.Id, 25);
                }
                else if (label.Id == "RPerson")
                {
                    labelContentCmd += TextToHex(label.Text, label.Id, 25);
                }
                else
                {
                    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
                             + "^FT180,420^BY3,2.4,50^BKN,N,80,Y,N,a,a" //BKN,N,150,Y,N,A,A
                             + barcodeNo
                             + "^PQ1,0,1,Y^XZ";
            RawPrinterHelper.SendStringToPrinter(printerName, content);
            #endregion
        }
Exemplo n.º 3
0
        /// <summary>
        /// 打印标签
        /// </summary>
        /// <param name="printerName"></param>
        /// <param name="labels"></param>
        private void ZPLPrintLabelsWithHexText(string printerName, Label[] labels)
        {
            string labelIdCmd      = string.Empty;
            string labelContentCmd = string.Empty;

            foreach (Label 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";

            RawPrinterHelper.SendStringToPrinter(printerName, content);
        }