# -*- coding: utf-8 -*-
# 先安装 BarTender 程序
# 然后找到 Interop.BarTender.dll 文件 拷贝到 当前目录下并改名为 BarTender.dll
# 再安装库 pip install pythonnet
import clr,os,sys
currentFolder = os.getcwd() # 获取当前路径,
sys.path.append(currentFolder) # 加载当前路径, 否则clr.AddReference("BarTender")会报找不到文件
clr.AddReference("BarTender") # 这里不需要 .dll 后缀
# 载入一堆要用到的东西,也可以直接 from BarTender import *
# 下面这句话不能写入函数里
from BarTender import Formats,Application,BtCacheFlushInterval,BtSaveOptions
# 创建 BarTender 的 Application
btApp = Application()
# 打开标签模板文件
btwfilename = currentFolder + "\\test.btw"
btformat = btApp.Formats.Open(btwfilename, False, "")
# 设置打印机
btformat.PrintSetup.Printer = "Microsoft Print to PDF"
# 给标签中的变量填值
btformat.SetNamedSubStringValue("xh", "诺贝丽仿石涂料")
btformat.SetNamedSubStringValue("zl", "20 Kg")
btformat.SetNamedSubStringValue("ph", "20191001123")
# 设置打印张数
btformat.PrintSetup.IdenticalCopiesOfLabel = 1
# 打印
btformat.PrintOut()
btformat.PrintSetup.Cache.FlushInterval = BtCacheFlushInterval.btCacheFlushPerSession
# 关闭
btformat.Close(BtSaveOptions.btDoNotSaveChanges)
btApp.Quit()
网友评论