using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
namespace Zebra
{
/// <summary>
/// ZPL帮助类
/// </summary>
public class ZebraHelper
{
/*
* 打印中文先引用Fnthex32.dll
dll控件常规安装方法(仅供参考):
下面是32系统的注册bat文件
可将下面的代码保存为“注册.bat“,放到dll目录,就会自动完成dll注册(win98不支持)。
@echo 开始注册
copy Fnthex32.dll %windir%\system32\
regsvr32 %windir%\system32\Fnthex32.dll /s
@echo Fnthex32.dll注册成功
@pause
下面是64系统的注册bat文件
@echo 开始注册
copy Fnthex32.dll %windir%\SysWOW64\
regsvr32 %windir%\SysWOW64\Fnthex32.dll /s
@echo Fnthex32.dll注册成功
@pause
*
*
ZebraHelper zh = new ZebraHelper();
StringBuilder builder = new StringBuilder();
builder.AppendLine(zh.ZPL_Start());
builder.AppendLine(zh.ZPL_PageSet(40, 80));
builder.AppendLine(zh.ZPL_DrawCHText("上善若水 厚德载物", "宋体", 40, 40, 0, 32, 0, 1, 0));
builder.AppendLine(zh.ZPL_DrawBarcode(40, 150, 3, 2, 40, "111112222233333"));
builder.AppendLine(zh.ZPL_DrawENText("111112222233333", "A", 30, 205, "N", 30, 50));
builder.AppendLine(zh.ZPL_DrawRectangle(20,20,2,700,700));
builder.AppendLine(zh.ZPL_End());
string a = builder.ToString();
//打印
zh.CmdDos("c:\\c.txt", a);
*/
public string ZPL_Start()
{
StringBuilder builder = new StringBuilder();
builder.AppendLine("^XA"); //指令块的开始
builder.AppendLine("^MD30"); //MD是设置色带颜色的深度
return builder.ToString();
}
public string ZPL_End()
{
StringBuilder builder = new StringBuilder();
builder.AppendLine("^XZ"); //指令块的结束
return builder.ToString();
}
/// <summary>
/// 设置打印标签纸边距
/// </summary>
/// <param name="printX">标签纸边距x坐标</param>
/// <param name="printY">标签纸边距y坐标</param>
/// <returns></returns>
public string ZPL_PageSet(int printX, int printY)
{
StringBuilder builder = new StringBuilder();
builder.AppendLine("^LH" + printX + "," + printY); //定义条码纸边距 80 10
return builder.ToString();
}
/// <summary>
/// 打印凭条设置
/// </summary>
/// <param name="width">凭条宽度</param>
ZPL斑马语言,C#打印类实例
最新推荐文章于 2023-08-06 15:06:34 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)