c# Bartender打印开发详解

本文分享了使用Bartender进行打印开发的两种方法:通过引用Bartender自带DLL及利用COM组件。并详细介绍了每种方法的具体实现步骤,同时记录了在远程调用Bartender打印时遇到的权限问题及其解决方案。

Bartender 打印开发遇到的坑

打印的写法,目前知道两种实现
1.引用 插入Bartender 自带dll,写法如下:
在这里插入图片描述
(一般在安装SDK里,可以找到dll)

using (Engine btEngine = new Engine())
{
btEngine.Start();
//Lable 路径
LabelFormatDocument btFormat = btEngine.Documents.Open(@“C:\Users\Administrator\Desktop\Bartender_\Labels\Outer.btw”);
//如何传参 命名具名数据源 赋予对应的 key<>value
btFormat.SubStrings[“ProductName”].Value = “test1”;
//传入打印机名称
btFormat.PrintSetup.PrinterName = “ZDesigner ZT410-300dpi ZPL”;
//打印张数
btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
btFormat.Print(“UID Printing Job”, 1);
btFormat.Close(SaveOptions.DoNotSaveChanges);
btEngine.Stop();
}
2.用 COM Bartender,写法如下:
在这里插入图片描述
(这个需要安装Bartender软件,自动寻找)
// Declare a BarTender application variable
BarTender.Application btApp;
BarTender.Format bFormat;
//Label路径位置
string strPath = @"";
// Create a new instance of BarTender
btApp = new BarTender.Application();
//打开label
bFormat = btApp.Formats.Open(strPath,false, “”);
//传入打印机名称
bFormat.Printer = “ZDesigner ZT410-300dpi ZPL”;
// 将对应变量赋值
bFormat.SetNamedSubStringValue(“ProductName”, “66666666666999”);
//打印张数
bFormat.IdenticalCopiesOfLabel = 1;
bFormat.PrintOut(false, false);
bFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges); //退出时是否保存标签
btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);

####### 在执行第二种方法时遇到点问题,我的业务场景是:我需要远程去调服务器上的Bartender打印,然后报错权限,错误如下:
Retrieving the COM class factory for component with CLSID {B9425246-4131-11D2-BE48-004005A04EDF} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
(百度了半天,才知道好像是权限问题)
解决如下—
<参考:https://blog.youkuaiyun.com/lllljz/article/details/44917545 (小生在这里谢过这位大神)>

评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值