• ZPL指令封装


     public partial class ZplCommand
        {
            /// <summary>
            /// 构造函数
            /// </summary>
            public ZplCommand()
            {
            }
    
            /// <summary>
            /// 开始指令 ^XA
            /// </summary>
            /// <returns></returns>
            public string ZPL_Start()
            {
                return "^XA";
            }
    
            /// <summary>
            /// 结束指令
            /// </summary>
            /// <returns></returns>
            public string ZPL_End()
            {
                return "^XZ";
            }
    
            /// <summary>
            /// 设置打印纸张大小
            /// ^PW{0}:打印宽度,如果宽度较小,则会出现打印不全的效果
            /// ^LL{0} 标签长度
            /// </summary>
            /// <param name="Width">打印纸的宽度</param>
            /// <param name="Height">打印纸长度</param>
            /// <returns></returns>
            public string ZPL_PageSize(int Width,int Height)
            {
                return string.Format("^PW{0}^LL{1}", Width, Height);
            }
    
            /// <summary>
            /// 设置打印纸边距
            /// ^LH{0},{1}
            /// </summary>
            /// <param name="Left">左边距</param>
            /// <param name="Top">右边距</param>
            /// <returns></returns>
            public string ZPL_MarginBorder(int Left, int Top)
            {
                return string.Format("^LH{0},{1}", Left, Top);
            }
    
            /// <summary>
            /// 切刀指令
            /// ^MM  C = 切刀 Y = 非连续纸
            /// </summary>
            /// <returns></returns>
            public string ZPL_Cutter()
            {
                return "^MMC,Y";
            }
    
            /// <summary>
            /// 打印英文文本
            /// </summary>
            /// <param name="Content">打印文本内容</param>
            /// <param name="FontName">打印字体</param>
            /// <param name="Left">左边距</param>
            /// <param name="Top">顶边距</param>
            /// <param name="Orient">旋转角度 N = 正常 (Normal) R = 顺时针旋转90度(Roated) I = 顺时针旋转180度(Inverted) B = 顺时针旋转270度 (Bottom)</param>
            /// <param name="Height">字体高度</param>
            /// <param name="Width">字体宽度</param>
            /// <returns></returns>
            public string ZPL_EnText(string Content, string FontName, int Left, int Top, string Orient, int Height, int Width)
            {
                string command = "^FO{1},{2}^A" + FontName + "{3},{4},{5}^FD{0}^FS";
                return string.Format(command, Content, Left, Top, Orient, Height, Width);
            }
    
            /// <summary>  
            /// 中文处理,返回ZPL命令  
            /// </summary>  
            /// <param name="ChineseText">待转变中文内容</param>  
            /// <param name="FontName">字体名称</param>  
            /// <param name="startX">X坐标</param>  
            /// <param name="startY">Y坐标</param>  
            /// <param name="Orient">旋转角度0,90,180,270</param>  
            /// <param name="Height">字体高度</param>  
            /// <param name="Width">字体宽度,通常是0</param>  
            /// <param name="IsBold">1 变粗,0 正常</param>  
            /// <param name="IsItalic">1 斜体,0 正常</param>  
            /// <returns></returns>  
            public string ZPL_CHText(string ChineseText, string FontName, int startX, int startY, int Orient, int Height, int Width, int IsBold, int IsItalic)
            {
                StringBuilder sResult = new StringBuilder();
                StringBuilder hexbuf = new StringBuilder(21 * 1024);
                int count = ZplCommand.GETFONTHEX(ChineseText, FontName, Orient, Height, Width, IsBold, IsItalic, hexbuf);
                if (count > 0)
                {
                    string sEnd = "^FO" + startX.ToString() + "," + startY.ToString() + "^XGOUTSTR" + ",1,2^FS ";
                    sResult.AppendLine(hexbuf.ToString().Replace("OUTSTR01", "OUTSTR") + sEnd);
                }
                return sResult.ToString();
            }
    
            /// <summary>  
            /// 中文处理  
            /// </summary>  
            /// <param name="ChineseText">待转变中文内容</param>  
            /// <param name="FontName">字体名称</param>  
            /// <param name="Orient">旋转角度0,90,180,270</param>  
            /// <param name="Height">字体高度</param>  
            /// <param name="Width">字体宽度,通常是0</param>  
            /// <param name="IsBold">1 变粗,0 正常</param>  
            /// <param name="IsItalic">1 斜体,0 正常</param>  
            /// <param name="ReturnPicData">返回的图片字符</param>  
            /// <returns></returns>  
            [DllImport("fnthex32.dll")]
            public static extern int GETFONTHEX(string ChineseText,string FontName,int Orient,int Height,int Width,int IsBold,int IsItalic,StringBuilder ReturnPicData);
    
            /// <summary>  
            /// 中文处理  
            /// </summary>  
            /// <param name="ChineseText">待转变中文内容</param>  
            /// <param name="FontName">字体名称</param>  
            /// <param name="FileName">返回的图片字符重命</param>  
            /// <param name="Orient">旋转角度0,90,180,270</param>  
            /// <param name="Height">字体高度</param>  
            /// <param name="Width">字体宽度,通常是0</param>  
            /// <param name="IsBold">1 变粗,0 正常</param>  
            /// <param name="IsItalic">1 斜体,0 正常</param>  
            /// <param name="ReturnPicData">返回的图片字符</param>  
            /// <returns></returns>  
            [DllImport("fnthex32.dll")]
            public static extern int GETFONTHEX(string ChineseText,string FontName,string FileName,int Orient,int Height,int Width,int IsBold,int IsItalic,StringBuilder ReturnPicData);
    
            /// <summary>
            /// 打印Code128条码
            /// </summary>
            /// <param name="Left">左边距</param>
            /// <param name="Top">顶边距</param>
            /// <param name="Width">模块(窄条)宽 初始化值:2点 可接受的数值:1-10点</param>
            /// <param name="Ratio">宽条与窄条的比例 初始化值:3.0 可接受的数值:2.0到3.0,0.1的增量(对固定比例的条码无效)</param>
            /// <param name="Height">条码高度开机初始化值:10点 可接受的数值:1点到标签高度。</param>
            /// <param name="Content">条码内容 条码只能是英文字符</param>
            /// <returns></returns>
            public string ZPL_Barcode128(int Left, int Top, int Width, int Ratio, int Height, string Content)
            {
                string command = "^FO{0},{1}^BY{2},{3}^BCN,{4},N,N^FD{5}^FS";
                return string.Format(command, Left, Top, Width, Ratio, Height, Content);
            }
    
            /// <summary>
            /// 打印二维码
            /// </summary>
            /// <param name="Left">左边距</param>
            /// <param name="Top">顶边距</param>
            /// <param name="Conent">二维码内容</param>
            /// <returns></returns>
            public string ZPL_QRCode(int Left, int Top,string Conent)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("^FO{0},{1}", Left, Top);
                sb.Append("^BQ,2,7");
                sb.AppendFormat("^FDLA,{0}^FS", Conent);
                return sb.ToString();
            }
    
    
            public string ZPL_Image(int Left, int Top, int cl, int bch, string path)
            {
                return string.Empty;
            }
        }
    
  • 相关阅读:
    回发或回调参数无效。 问题的解决和思考
    母板页中的引用的图片,JS,css等路径问题
    Solution: 题解 CF1196E Connected Component on a Chessboard
    01/05/2020 我注册了博客园 I enrolled in Cnblogs.
    Basic Thought / Data Structure: 前缀和 Prefix Sum
    Basic Thought / Data Structure: 差分 Difference
    DotNet中异步编程(APM)的研究1异步编程介绍
    关于atl server 的感受(3) 一个我自以为豪的应用
    自己的博客,竟然要自己搜出来,太久没来了。
    关于atl server 的感受(2)
  • 原文地址:https://www.cnblogs.com/datacool/p/12888300.html
Copyright © 2020-2023  润新知