受欢迎的博客标签

BarTender 集成模式之一:集成模式总目录

Published

BarTender的几种集成模式。ActiveX COM集成,Commander的触发式集成,还有9.0版本后支持的.NET SDK的支持。

1.ActiveX COM:BarTender在你的机器上安装好后,会在机器上注册一个COM,你在程序中可以调用这个COM,使用他提供的方法和属性,进行BarTender的程序级控制。这个集成方式比较实用,对BarTender的版本要求低,不过因为是基本的COM使用,所以要求你对COM的接口比较熟悉,对整个BarTender的调用流程和细节比较清晰,对于COM接口的描述,大家可以参考Automation.chm这个帮助文档(在Seagull\BarTender Suite\BarTender目录下)。
2. Commander的触发式集成:简单来说,这个是通过配置BarTender,让他监视某个文件,当程序生成这个文件的时候,就会触发唤醒BarTender进行打印工作,这种方式我觉得不大好用,所以了解也不多,欢迎讨论交流。
3. .NET SDK:这个是9.0版本开始支持的一个适用于.NET框架的SDK,里面提供了很多类来进行BarTender的控制,由于这个SDK也是用.NET编写的,所以对于用在.NET下的集成非常方便,不过由于对版本有要求,所以要考虑客户的成本来使用。

4:Command-Line Interface: bartend.exe /F=partlist.btw /P /X

english:BarTender Integration Methods 

Although our example below of how to programmatically control BarTender uses C# as the programming language, when you are using C# or VB.NET, it is much easier to use the BarTender .NET SDKs instead of directly using the ActiveX Automation Interface

 

1.ActiveX COM

C#

首先添加引用,

{
//调用Bartender
btApp = new BarTender.Application();
//获取打印模板,指定打印机
btFormat = btApp.Formats.Open(Application.StartupPath + “\1DbarCode.btw”, false, “”);
// 同样标签的份数
btFormat.PrintSetup.IdenticalCopiesOfLabel = pageCount;
// 序列标签数
btFormat.PrintSetup.NumberSerializedLabels = 1;
//设置参数
btFormat.SetNamedSubStringValue(“1Dbarcode”, barcode);
//打印开始 第2个参数是 是否显示打印机属性的。可以设置打印机路径
btFormat.PrintOut(false, false);
//关闭摸板文件,并且关闭文件流
btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
//打印完毕
btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);

 

how to create bartender file(.btw) in C#

we can create empty barcode in bartender to use it in the application, we load the file, get the barcode then change its value:

private BarTender.Application GetApplication() {
if (barTenderApplication == null) {
barTenderApplication = new BarTender.Application();
    }
return barTenderApplication;
}
 
Format barTenderFormat = GetApplication().Formats.Open(fileName);
barTenderFormat.SetNamedSubStringValue("gh", txtFName.barTenderFormat.SetNamedSubStringValue("os", txtX.barTenderFormat.SetNamedSubStringValue("yo", txtY.Text);
string imageName = @"C:\Bartender 03.10.13\" + DateTime.Now.Millisecond + ".jpg";
barTenderFormat.ExportToFile(imageName, "jpg", BtColors.btColors16, BtResolution.btResolutionPrinter, BtSaveOptions.btSaveChanges);
barTenderFormat.Close(BtSaveOptions.btSaveChanges);
Bitmap bMap = new Bitmap(new Bitmap(imageName), pictureBox.Width, pictureBox.Height);
pictureBox.Image = bMap;

 

2..NET SDK


首先添加引用,在.NET的TAB里面可以找到Seagull.BarTender.Print
        然后,在程序里添加命名空间引用 “using Seagull.BarTender.Print;”
        之后程序的简单使用如下:

 //new an BarTender engine
          Engine engine = new Engine(true);
          //use the engine to open a format document to return a LabelFormatDocument object
          LabelFormatDocument format = engine.Documents.Open("c:\\test.btw");
          //use the LabelFormatDocument object to print
          format.Print("Select printer", out messages);

 

BarTender Command-Line Interface

http://help.seagullscientific.com/2016/en/Content/file_command_params_command_summary.htm

You can automate what BarTender does using command line parameters. The syntax of a command line is:

bartend.exe /F=partlist.btw /P /X