c#调用Bartender标签模板打印
Bartender标签打印软件挺好用的,模板可视化,参数也好调整,我用的是这个版本
先在电脑上装好Bartender软件
然后在VS项目中,添加引用 ,选择COM组件,搜索Bartender,确定引用BarTender 10.1
在项目中创建BarTenderPrint类
/// <summary> /// 打印标签类 /// </summary> public class BarTenderPrint { /// <summary> /// 打开标签文件 /// </summary> public static BarTender.Application btApp = new BarTender.Application(); /// <summary> /// BarTender运行软件 /// </summary> public static BarTender.Format btFormat = new BarTender.Format(); /// <summary> /// 打印 /// </summary> /// <param name="printerName">打印机名称</param> /// <param name="btFileName">打印文件</param> /// <param name="dict">内容字典</param> /// <param name="CopiesOfLabel">打印数量</param> public static bool Print(string printerName, string btFileName, Dictionary<string, string> dict, int CopiesOfLabel) { try { btFormat = btApp.Formats.Open(btFileName); btFormat.PrintSetup.Printer = printerName; btFormat.IdenticalCopiesOfLabel = CopiesOfLabel; foreach (var item in dict) { btFormat.SetNamedSubStringValue(item.Key, item.Value); } btFormat.PrintOut(false, false); //不保存标签退出 btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges); return true; } catch (Exception ex) { MessageBox.Show("【打印机"+ printerName+"】", ex.Message); return false; } } }
调用打印函数
bool Falg = false;
string barcode = "035838223A05003W";
string rohsLabel = "EXS 0040kTH16FN01U22";
string itemVersion = "0";
string itemModel = "E3";
string factoryCode = "R6";
//传递打印内容,Key-Vaule
Dictionary<string, string> dic = new Dictionary<string, string>() { {"QRcode128",barcode}, {"ITEM",itemModel}, {"Version",itemVersion }, {"ROHS",rohsLabel }, {"Producer",factoryCode } }; Flag = BarTenderPrint.Print("SN", GlobalValue.SNPrintPath, dic, 1);//表示有一个名称为SN的打印机,然后打印模板的路径,打印内容,打印数量
打印模板这样设置
需要注意的是,如果要将内容值可更改,那么就要给标签对象改一个名称