引用COM库
Seagull\BarTender 2022\SDK\Assemblies\Seagull.BarTender.Print.dll
启动引擎
// 启动引擎(第一次运行耗时较多)
Engine btEngine = new Engine(true)
打开BTW文档并指定打印机
// 打开标签
LabelFormatDocument btFormat = btEngine.Documents.Open(文件名, 打印机名);
给具名字段赋值
// 设置数据 字段信息 Directory<string, string>
foreach(var kv in 字段信息)
{
btFormat.SubStrings[kv.Key].Value = kv.Value;
}
设置数量
// 对应软件里的序号数量
btFormat.PrintSetup.NumberOfSerializedLabels = 序号数量;
// 对应软件里每个序号的copies数量
btFormat.PrintSetup.IdenticalCopiesOfLabel = 打印数量;
设置纸张大小
btFormat.PageSetup.PaperWidth = 纸张宽度;
btFormat.PageSetup.PaperHeight = 纸张高度;
打印并获得返回值
// 第一个参数为JobName
Result result = btFormat.Print("", out Messages messages);
// Result为枚举 例如if (result == Result.Success)
// Messages是IEnumerable<Message> 迭代可得到更多详细信息
foreach(Message msg in messages)
{
Console.WriteLine(msg.ID);
Console.WriteLine(msg.Text);
// msg.xx 还有更多
}
整体代码
// 启动引擎
using (Engine btEngine = new Engine(true))
{
// 打开标签
LabelFormatDocument btFormat = btEngine.Documents.Open(文件名, 打印机名);
// 设置数据
foreach(var kv in 字段信息)
{
btFormat.SubStrings[kv.Key].Value = kv.Value;
}
// 设置数量
btFormat.PrintSetup.NumberOfSerializedLabels = 序号数量;
btFormat.PrintSetup.IdenticalCopiesOfLabel = 打印数量;
btFormat.PageSetup.PaperWidth = 纸张宽度;
btFormat.PageSetup.PaperHeight = 纸张高度;
Result result = btFormat.Print("", out Messages messages);
// 关闭
btFormat.Close(SaveOptions.DoNotSaveChanges);
btEngine.Stop();
// 返回信息
Console.WriteLine(result.ToString()); // Success
foreach(Message msg in messages)
{
Console.WriteLine(msg.ID);
Console.WriteLine(msg.Text);
}
}
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容