C#怎么调用Bartender的COM组件打印
以下是在C#中调用Bartender的COM组件打印的步骤:
- 在Visual Studio中创建一个新的C#项目。
- 在项目中添加对Bartender的COM组件的引用。右键单击“引用”文件夹,选择“添加引用”,然后在“COM”选项卡中找到Bartender COM组件并添加它。
- 在代码中实例化Bartender的Application对象,并设置打印机名称和标签文件路径。
using Seagull.BarTender.Print;
// 实例化Bartender的Application对象
Engine btEngine = new Engine();
LabelFormatDocument btFormat = null;
btEngine.Start();
btFormat = btEngine.Documents.Open("标签文件路径");
// 设置打印机名称
btFormat.PrintSetup.PrinterName = "打印机名称";
// 在标签上设置数据源
btFormat.SetNamedSubStringValue("数据源名称", "数据源值");
- 调用Bartender的Print方法打印标签。
btFormat.Print("标签数量");
完整的代码示例:
using Seagull.BarTender.Print;
public void PrintLabel()
{
// 实例化Bartender的Application对象
Engine btEngine = new Engine();
LabelFormatDocument btFormat = null;
btEngine.Start();
btFormat = btEngine.Documents.Open("标签文件路径");
// 设置打印机名称
btFormat.PrintSetup.PrinterName = "打印机名称";
// 在标签上设置数据源
btFormat.SetNamedSubStringValue("数据源名称", "数据源值");
// 打印标签
btFormat.Print("标签数量");
// 关闭Bartender连接
btFormat.Close(SaveOptions.DoNotSaveChanges);
btEngine.Stop();
}
原文地址: https://www.cveoy.top/t/topic/bs9J 著作权归作者所有。请勿转载和采集!