C#使用BarTender打印Label

来源:互联网 发布:网络带来的危害 编辑:程序博客网 时间:2024/05/29 07:17

1.首先下载BarTender。

2.在CS代码中引用using Seagull.BarTender.Print,否则无法打印。

3.使用BarTender制做打印模板SN.btw(eg)。

3.代码:

   本例:只做一个简单的SN的打印。

     public void Print(string strSN)
        {
            string tempPath = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Temp\\SN.btw";
            string tempPath1 = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Temp\\SN.btw";
            Engine engine = new Engine(true);
            //use the engine to open a format document to return a LabelFormatDocument object
            engine.Start();
            LabelFormatDocument format = engine.Documents.Open(tempPath1, this.txtPrint.Text);// this.txtPrint.Text打印机名
            //LabelFormatDocument format = engine.Documents.Open(tempPath);
            FileStream fs = new FileStream(tempPath, FileMode.Open);//可以是其他重载方法 
            byte[] byData = new byte[fs.Length];
            fs.Read(byData, 0, byData.Length);
            fs.Close();
            format.SubStrings["SN"].Value = strSN; //给打印模板中的参数SN赋值 。
            //format.PrintSetup.PrinterName = @"HP1022_mis";
            //engine.Stop(SaveOptions.SaveChanges); 
            format.PrintSetup.IdenticalCopiesOfLabel = int.Parse(this.txtPrintCount.Text == "" ? "1" : this.txtPrintCount.Text);
            format.Print();
            engine.Stop();

            lblMessage.Text = "SN:" + strSN.ToUpper() + "打印成功,请再输入SN!";
            this.txtWO.SelectAll();
            this.txtWO.Focus();
        }



原创粉丝点击