近期用bartend,有两种方法可以呼叫
1.呼叫bartend.exe
2.採用bartend.dll(版本11.1.3.1)
工具
1.bartend版本 :BarTender Designer 2019 R3 Enterprise 版本
2.VS2019 C#
c#
方法1:呼叫bartend.exe
//宣告P,执行其它外部程式 Process p; //载入位置 BarTend = @"C:\Program Files\Seagull\BarTender 2019\bartend.exe";//执行Bartend.exe Template = @"C:\test\temp.btw";//列印的样版 PrintValue = @"C:\test\textcontent.txt";//内容 private void button1_Click(object sender, EventArgs e) { string sub_nam = @"/F="+ Template + " /D="+ PrintValue + " /P /X " + Convert.ToChar(10); try { //启动处理序 p = Process.Start(BarTend, sub_nam);//start(执行档,传递值) } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } finally { if (p != null) { p.Close(); p.Dispose(); p = null; } } }
Bartend方面
资料库->右键资料库连线设定->下图,再选择列印的内容,例如:txt,csv
这里要先指定,否则再c#再传送新的列印内容,它会出现警告-找不到印的内容的档案
优点:c# 程式简单,只要呼叫bartend.exe就可以列印
缺点:c# 点击多次Process.statr 反而呼叫bartend.exe没有反应,要多按几次
方法2:採用bartend.dll(版本11.1.3.1)
滙入DLL
来源: C:\Program Files\Seagull\BarTender 2019\SDK\Assemblies\Seagull.BarTender.Print.dll
C#
using Seagull.BarTender.Print; //重要 private void button1_Click(object sender, EventArgs e) { try { Engine btEngine = new Engine(); btEngine.Start(); string lj = @"C:\test\btwtest.btw"; LabelFormatDocument btFormat = btEngine.Documents.Open(lj); //对模版相应栏位进行赋值 btFormat.SubStrings["1"].Value = "44"; btFormat.SubStrings["2"].Value = "55"; btFormat.SubStrings["3"].Value = "FRVGT789"; //指定印表机名 btFormat.PrintSetup.PrinterName = "标籤机名字"; //改变标籤列印数份连载 btFormat.PrintSetup.NumberOfSerializedLabels = 1; //列印份数 btFormat.PrintSetup.IdenticalCopiesOfLabel = 1; Messages messages; int waitout = 10000; // 10秒 超时 Result nResult1 = btFormat.Print("标籤列印软体", waitout, out messages); btFormat.PrintSetup.Cache.FlushInterval = CacheFlushInterval.PerSession; //不储存对开启模板的修改 //btFormat.Close(SaveOptions.DoNotSaveChanges); //结束列印引擎 btEngine.Stop(); } catch (Exception ex) { MessageBox.Show("Exception: " + ex.Message); return; } }
bartend方面
拉下物件,如下图
拉下”文字”按右键选”属性”,找到”资料来源”->文字範例,将”名称”设1。
PS: ”名称”设1是c#列印内容
选QRCode,将文字(12345678)给隐藏,用属性->选”123可读性”->点”无”。
找到”资料来源”将”名称”设3。
C#进行列印会出现错误
执行程式(RUN)时
System.BadImageFormatException HResult=0x8007000B Message=无法载入档案或组件 'Seagull.BarTender.Print, Version=11.1.3.1, Culture=neutral, PublicKeyToken=109ff779a1b4cbc7' 或其相依性的其中之一。
解决方法
专案->属性->应用程式->目标Framework将4.6.1 改为 4.0
改NET.Framework4 即可
但我再改回用Framework将4.6.1,就不会出现错了。
PS:可能旧版改回来没效
参考网站