C#调用Bartender打印标签

2025-10-17 06:08:31

1、电脑装 BarTender软件,可到官网下载试用版本

C#调用Bartender打印标签

2、创建WinForm项目,添加引用,浏览引用Seagull.BarTender.Print,这个DLL路径一般在C:\Program Files (x86)\Seagull\BarTender Suite\SDK\Assemblies

特别注意要在程序中写入引用 using Seagull.BarTender.Print;//这里不能少

C#调用Bartender打印标签

3、设置程序界面

C#调用Bartender打印标签

4、开始做个DEMO打印,VS2012代码如下

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

using Seagull.BarTender.Print;//这里不能少

namespace WindowsFormsApplication4

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            try 

            { 

                Engine btEngine = new Engine(); 

                btEngine.Start(); 

                string lj = AppDomain.CurrentDomain.BaseDirectory + "test.btw";  //test.btw是BT的模板

                LabelFormatDocument btFormat = btEngine.Documents.Open(lj); 

                //对BTW模版相应字段进行赋值 

                btFormat.SubStrings["name"].Value = spname.Text; 

                btFormat.SubStrings["code"].Value = spcode.Text; 

                //指定打印机名 

                btFormat.PrintSetup.PrinterName = "TSC2018"; 

                //改变标签打印数份连载 

                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("错误信息: " + ex.Message); 

                return; 

            } 

        

        }

    }

}

5、打开BarTender进行设计模板,把文本对象与条形码对象拖入设计区域,,同时对对象进行命名,这个很重要,名字将影响程序调用使用的。如本程序中,模板名品名是name,条形码名是code,模板保存名为test.btw,并放在程序运行的目录下。

C#调用Bartender打印标签

C#调用Bartender打印标签

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢