通过找IP地址的方式传输给打印机(必须是后台和打印机必须是再同一个网段)
public bool PrintZPL(Barcode_Model bm, string ipport, ref string ErrMsg)
{
List<string> strlist = new List<string>();
strlist.Add(Man(bm));
int port = 0;
try
{
bool res = int.TryParse(ipport.Split(':')[1], out port);
if (!res)
{
ErrMsg = "端口格式错误";
return false;
}
}
catch
{
ErrMsg = "端口格式错误";
return false;
}
//打印
SocketHelper sh = new SocketHelper(ipport.Split(':')[0], port);
if (!sh.Send(strlist, ref ErrMsg))
{
return false;
}
return true;
}
public static string Man(Barcode_Model model)
{
StringBuilder sbPrint = new StringBuilder();
StringBuilder sbReturn = new StringBuilder(10240);
FontConvertBmp fcb = new FontConvertBmp();
//标题
fcb.GETFONTHEX("信息标签", false, "黑体", "title", 80, 0, true, false, sbReturn);
sbPrint.Append(sbReturn.ToString());
//内容
fcb.GETFONTHEX("名称", false, "黑体", "name", 50, 0, true, false, sbReturn);
sbPrint.Append(sbReturn.ToString());
fcb.GETFONTHEX(model.RecPeo, false, "黑体", "name2", 60, 0, true, false, sbReturn);
sbPrint.Append(sbReturn.ToString());
fcb.GETFONTHEX("编号", false, "黑体", "no", 50, 0, true, false, sbReturn);
sbPrint.Append(sbReturn.ToString());
fcb.GETFONTHEX(model.SerialNo, false, "黑体", "no2", 60, 0, true, false, sbReturn);
sbPrint.Append(sbReturn.ToString());
//定位
sbPrint.Append("^XA");
sbPrint.Append("^PW0610^LL0730^LS0");
sbPrint.Append("^FO50,60^XGtitle^FS");
//横线
sbPrint.Append("^FO0,150^GB610,0,3^FS");
//体
sbPrint.Append("^FO30,180 ^XGname^FS");
sbPrint.Append("^FO30,250 ^XGname2^FS");
sbPrint.Append("^FO30,340^XGno^FS");
sbPrint.Append("^FO30,410^XGno2^FS");
//横线
sbPrint.Append("^FO0,490^GB610,0,3^FS");
//FT45,180^BQN,2,3
//BQ FT35,180^BQN,2,3
sbPrint.Append("^FT230,750^BQN,2,9^FDQA," + model.SerialNo + "^FS");
sbPrint.Append("^XZ");
//删除图片
sbPrint.Append("^XA");
sbPrint.Append("^IDR:title^FS");
sbPrint.Append("^IDR:name^FS");
sbPrint.Append("^IDR:name2^FS");
sbPrint.Append("^IDR:no^FS");
sbPrint.Append("^IDR:no2^FS");
sbPrint.Append("^XZ");
return sbPrint.ToString();
}