使用winfrom调用BarTender实现标签的打印


1、实现BarTender的打印。

  ①:第一步:首先要引用Interop.BarTender.dll文件

  

  ② :第二步,直接贴代码

public partial class Form1 : Form
    {
        private BarTender.Application btApp;            //Bartender 应用实例
        private BarTender.Format btFormat;              //Bartender 样式
        public FormFT()
        {
            InitializeComponent();
        }

        //标签打印
        private void button_Click(object sender, EventArgs e)
        {
            btApp = new BarTender.Application();
            try
            {
                btFormat = btApp.Formats.Open(@"D:\标签.btw", false, "");  //标签地址
            }
            catch (Exception)
            {
                MessageBox.Show(@"未找到D:\标签!", "提示");
                return;
            }
            btFormat.PrintSetup.NumberSerializedLabels = 1; //设置打印份数//生产型号
            btFormat.SetNamedSubStringValue("product_version", txt_1.Text);

btFormat.PrintOut(true, false); //第二个参数设置是否跳出打印属性; btFormat.Close(BarTender.BtSaveOptions.btSaveChanges); //退出时是否保存标签 btApp.Quit(BarTender.BtSaveOptions.btSaveChanges);//退出时同步退出bartender进程 } }

 

  ③:上面代码要注意几个地方

    1、要把标签放到电脑的一个地方(如上的地址:D:\标签.btw)

    2、txt_1.Text就是winfrom上面名称为txt_1的文本框的内容.

    

    3、product_version就是BarTender里面的文本名称。(如果模板上面没有这个名称的话,会报错)

    

    4、就是打印模板的电脑上面一定要安装了BarTender这个软件(即只有一个模板是不够的,还要安装软件才行),不然程序会报错。

 

2、附上BarTender软件的样子,下载地址就不提供了,自己找。

  模板的样子

  

  软件的样子

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM