C#调用barTender打印标签示例

使用的电脑需要先安装BarTender 

 

 

 我封装成一个类

using System;
using System.Windows.Forms;namespace FT_Tools
{public class SysContext{public static BarTender.Application btapp = new BarTender.Application();public static BarTender.Format btFormat;public void Quit(){SysContext.btapp.Quit(BarTender.BtSaveOptions.btSaveChanges);//界面退出时同步退出bartender进程}private static bool btPrint_Test(string modelPath,string txt,string barcode ){try{btFormat = btapp.Formats.Open(modelPath, false, ""); //System.Windows.Forms.Application.StartupPath + @"\1.btw"btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;//打印份数btFormat.PrintSetup.NumberSerializedLabels = 1;//序列标签数btFormat.SetNamedSubStringValue("打印文本", txt.Trim());btFormat.SetNamedSubStringValue("打印条码", barcode.Trim());btFormat.PrintOut(true, false);//第二个false设置打印时是否跳出打印属性btFormat.Close(BarTender.BtSaveOptions.btSaveChanges); //退出时是否保存标签return true;}catch (Exception ex){MessageBox.Show(ex.Message);return false;}}}}

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace BarTenderDemo
{public partial class Form1 : Form{private BarTender.Application btAPP;private BarTender.Format btFormat;//SELECT MaterielId,ProductBigPackId,NetWeight,GrossWeight,num //FROM Make_ProductBigPack mpb//LEFT JOIN Make_TaskInfo mti ON mpb.TaskId=mti.TaskId//WHERE ProductBigPackId=''public Form1(){InitializeComponent();}private void Form1_Load(object sender, EventArgs e){btAPP = new BarTender.Application();}private void btPrint_Click(object sender, EventArgs e){try{btFormat = btAPP.Formats.Open(System.Windows.Forms.Application.StartupPath+@"\1.btw", false, "");btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;//打印份数btFormat.PrintSetup.NumberSerializedLabels = 1;//序列标签数btFormat.SetNamedSubStringValue("打印文本", txtMemo.Text.Trim());btFormat.SetNamedSubStringValue("打印条码", txtBarcode.Text.Trim());btFormat.PrintOut(true, false);//第二个false设置打印时是否跳出打印属性btFormat.Close(BarTender.BtSaveOptions.btSaveChanges); //退出时是否保存标签}catch(Exception ex){MessageBox.Show(ex.Message);}}private void Form1_FormClosed(object sender, FormClosedEventArgs e){btAPP.Quit(BarTender.BtSaveOptions.btSaveChanges);//界面退出时同步退出bartender进程}}
}

示例2:与上面一样的。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Runtime.InteropServices;
using BarTender;
using System.Text;
using Newtonsoft.Json;namespace bartenderService
{/// <summary>/// BartenderWebService 的摘要说明/// </summary>[WebService(Namespace = "http://tempuri.org/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][System.ComponentModel.ToolboxItem(false)]// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 // [System.Web.Script.Services.ScriptService]public class SysContext{public static BarTender.Application btapp = new BarTender.Application();public static BarTender.Format btfat;}public class BartenderWebService : System.Web.Services.WebService{[WebMethod]public string HelloWorld(){return "Hello World";}[WebMethod]public string GetTestLabelJson(){printContext pt=new printContext();pt.data = new List<printCell>();printCell cell=new printCell();pt.modelName = "气体检测仪.btw";pt.printDateStr = "生产日期";pt.printFBStr = "防爆证号";pt.printGasStr = "测量气体";pt.printSNStr = "产品编号";pt.printTELStr = "热线电话";pt.printVolStr = "工作电压";pt.printRangeStr = "检测范围";cell.printDate = "2019.12";cell.printFB = "CNEX17.0263";cell.printGas = "可燃气体";cell.printRange = "0-100";cell.printVol = "24V";cell.printUnit = "%LEL";cell.printSN = "226013221";pt.data.Add(cell);cell.printGas = "氨气";cell.printUnit = "PPM";pt.data.Add(cell);return JsonConvert.SerializeObject(pt);}[WebMethod]public string PrintLabel(string jsonstr){int printcount = 0,i=0;string path = System.AppDomain.CurrentDomain.BaseDirectory + "model";string file_ini = path + "\\configure.ini";//pt.modelName + pt.data[1].printRange + pt.data[1].printGas//Newtonsoft.Json.Linq.JArray.Parse(jsonstr);printContext pt = JsonConvert.DeserializeObject<printContext>(jsonstr);if (pt.modelName == null)pt.modelName = "";if (pt.modelName == "")pt.modelName = "气体检测仪.btw";try{SysContext.btfat = SysContext.btapp.Formats.Open(path + "\\" + pt.modelName, false, "");}catch{pt.modelName = "气体检测仪.btw";SysContext.btfat = SysContext.btapp.Formats.Open(path + "\\" + pt.modelName, false, "");}SysContext.btfat.PrintSetup.IdenticalCopiesOfLabel = 1;SysContext.btapp.Visible = false;printcount = pt.data.Count();for(i=0;i<printcount;i++){SysContext.btfat.SetNamedSubStringValue("BT_Gas", String.Format(pt.printGasStr+":"+pt.data[i].printGas));SysContext.btfat.SetNamedSubStringValue("BT_Range", String.Format(pt.printRangeStr+":"+pt.data[i].printRange+ pt.data[i].printUnit));SysContext.btfat.SetNamedSubStringValue("BT_Vol", String.Format(pt.printVolStr + ":" + pt.data[i].printVol));SysContext.btfat.SetNamedSubStringValue("BT_SN", String.Format(pt.printSNStr + ":" + pt.data[i].printSN));SysContext.btfat.SetNamedSubStringValue("BT_DATE", String.Format(pt.printDateStr + ":" + pt.data[i].printDate));SysContext.btfat.SetNamedSubStringValue("BT_FB", String.Format(pt.printFBStr + ":" + pt.data[i].printFB));if(pt.data[i].printTEL!=""&& pt.data[i].printTEL !=null)SysContext.btfat.SetNamedSubStringValue("BT_TEL", String.Format(pt.printTELStr + ":" + pt.data[i].printTEL));SysContext.btfat.PrintOut(false, false);} return "ok";}}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/61318.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

200 套基于Java开发的Java毕业设计实战项目(含源码+说明文档)

文章目录 简介前言第一部分第二部分部分截图源码咨询 简介 博主介绍&#xff1a;✌程序员徐师兄、7年大厂程序员经历。全网粉丝30W、csdn博客专家、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ 前言 对于java方向的毕业设计题目选题&#xf…

2024河南光伏展,河南郑州太阳能光伏展,郑州光伏产业展览会

2024第四届中国&#xff08;郑州&#xff09;太阳能光伏及储能产业展览会   时间&#xff1a;2024年2月26-28日 地点&#xff1a;郑州.中原国际博览中心 在过去的几年中&#xff0c;太阳能光伏及储能技术得到了快速的发展和广泛的应用。为了进一步推动这一产业的发展和进步&…

Densenet模型详解

模型介绍 DenseNet的主要思想是密集连接&#xff0c;它在卷积神经网络&#xff08;CNN&#xff09;中引入了密集块&#xff08;Dense Block&#xff09;&#xff0c;在这些块中&#xff0c;每个层都与前面所有层直接连接。这种设计可以让信息更快速地传播&#xff0c;有助于解…

实力征服每寸版图|昂首资本Anzo Capital狂揽“年度最佳经纪商“和“最佳青年导师”双料大奖

棉兰老岛交易者博览会在Tibungco 的 RTC-KorPhil 职业培训中心多功能厅举办。在本次博览会上&#xff0c;Anzo Capital 昂首资本脱颖而出斩获“2023年度最佳经纪商”&#xff0c;Anzo Capital 官方金融教育专家Joseph Lejarde斩获“最佳青年导师”双料大奖。 棉兰老岛交易者…

zabbix语言无法选择中文--zabbix安装配置中文

You are not able to choose some of the languages, because locales for them are not installed on the web server. 1、安装wget yum -y install wget 2、下载中文中文字体并配置 wget https://github.com/echohn/zabbix-zh_CN/archive/master.zip yum -y install unzip un…

Go学习第十天

打印报错堆栈信息 安装errors包 go get github.com/pkg/errors 具体使用 // 新生成一个错误, 带堆栈信息 func New(message string) error//只附加新的信息 func WithMessage(err error, message string) error//只附加调用堆栈信息 func WithStack(err error) error//同时附…

【Vue】vue2预览显示quill富文本内容,vue-quill-editor回显页面,v-html回显富文本内容

文章目录 前言一、下载二、使用步骤1.引入样式2.html代码 总结 前言 提示&#xff1a;这里可以添加本文要记录的大概内容&#xff1a; vue后台框架&#xff0c;若依系统里有一个富文本编辑器&#xff0c;效果如下 在package.json里面查看&#xff0c;发现插件名叫quill 插件的…

美国纽约10日游

一、前言 我有两周断更了&#xff0c;原因是去纽约只顾着玩&#xff0c;没时间写&#xff0c;今天有时间正好和大家分享一下去纽约的攻略 二、以下是一个10天去美国纽约旅游的攻略&#xff0c;十万以内&#xff0c;包括机票、酒店、交通、餐饮和景点门票等费用&#xff1a; 第…

java 泛型作为方法的返回值的封装

问题背景 业务需要&#xff0c;经常需要http方式调用某服务&#xff0c;然后某服务返回特定类型的返回内容。 类似 String resStr xxxHttpClient.post() &#xff0c;然后它返回一个字符串&#xff0c;你还需要反序列化成某种格式的。 返回值可以反序列化成的形式如下&#…

音视频 ffplay简单过滤器

视频旋转 ffplay -i test.mp4 -vf transpose1视频反转 ffplay test.mp4 -vf hflip ffplay test.mp4 -vf vflip视频旋转和反转 ffplay test.mp4 -vf hflip,transpose1音频变速播放 ffplay -i test.mp4 -af atempo2视频变速播放 ffplay -i test.mp4 -vf setptsPTS/2音视频同…

如何在Windows本地快速搭建SFTP文件服务器,并通过端口映射实现公网远程访问

文章目录 1. 搭建SFTP服务器1.1 下载 freesshd服务器软件1.3 启动SFTP服务1.4 添加用户1.5 保存所有配置 2 安装SFTP客户端FileZilla测试2.1 配置一个本地SFTP站点2.2 内网连接测试成功 3 使用cpolar内网穿透3.1 创建SFTP隧道3.2 查看在线隧道列表 4. 使用SFTP客户端&#xff0…

1.Python操作txt文本

文章目录 1.Python读取一个txt文件的内容并将其写入到另一个txt文件2.Python读取一个未知编码的文件并将其设置为指定编码格式3.Python实现txt文件中字符串的替换 1.Python读取一个txt文件的内容并将其写入到另一个txt文件 # -*- encoding:gb2312 -*- import chardetdef read_…

Linux命令awk详细用法

简介 awk 是一种强大的文本处理工具&#xff0c;用于在命令行环境下对文件或数据流进行逐行处理和分析。它是由 Alfred Aho、Peter Weinberger 和 Brian Kernighan 在 1977 年开发的&#xff0c;并以他们三人的姓氏命名。awk 在 Unix/Linux 系统中非常常见&#xff0c;也有 Win…

代码随想录算法训练营之JAVA|第四十一天|139. 单词拆分

今天是第 天刷leetcode&#xff0c;立个flag&#xff0c;打卡60天。 算法挑战链接 139. 单词拆分https://leetcode.cn/problems/word-break/ 第一想法 看完之后完全没有想法。 看完代码随想录之后的想法 这是一个完全背包的问题&#xff0c;使用完全背包的解法。 单词就…

leetcode7.整数反转-Java

题目 给你一个 32 位的有符号整数 x &#xff0c;返回将 x 中的数字部分反转后的结果。 如果反转后整数超过 32 位的有符号整数的范围 [−231, 231 − 1] &#xff0c;就返回 0。 假设环境不允许存储 64 位整数&#xff08;有符号或无符号&#xff09;。 7. 整数反转 - 力扣&a…

栈和队列(优先级队列)

一)删除字符串中所有相邻字符的重复项 1047. 删除字符串中的所有相邻重复项 - 力扣&#xff08;LeetCode&#xff09; 算法原理:栈结构模拟&#xff0c;只是需要遍历所有字符串中的字符&#xff0c;一次存放到栈里面即可&#xff0c;也是可以使用数组来模拟一个栈结构的: class…

RabbitMQ从原理到实战—基于Golang【万字详解】

文章目录 前言一、MQ是什么&#xff1f;优势劣势 二、MQ的用途1、应用解耦2、异步加速3、削峰填谷4、消息分发 三、RabbitMQ是什么1、AMQP 协议2、RabbitMQ 包含的要素3、RabbitMQ 基础架构 四、实战1、Simple模式(即最简单的收发模式)2、Work Queues 模型3、Publish/Subscribe…

如何查询Oracle的字符集

如何查询Oracle的字符集 很多人都碰到过因为字符集不同而使数据导入失败的情况。这涉及三方面的字符集&#xff0c;一是oracel server端的字符集&#xff0c;二是oracle client端的字符集;三是dmp文件的字符集。在做数据导入的时候&#xff0c;需要这三个字符集都一致才能正确…

Java学习笔记32——字符缓冲流

字符缓冲流 字符流字符缓冲流字符缓冲流的特有功能 IO流小结字节流字符流 字符流 字符缓冲流 BufferedWriter:将文本写入字符输出流&#xff0c;缓冲字符&#xff0c;以提供单个字符&#xff0c;数组和字符串的高效写入&#xff0c;可以指定缓冲区大小&#xff0c;或者可以接…

C++贪吃蛇(控制台版)

C自学精简实践教程 目录(必读) 目录 主要考察 需求 输入文件 运行效果 实现思路 枚举类型 enum class 启动代码 输入文件data.txt 的内容 参考答案 学生实现的效果 主要考察 模块划分 文本文件读取 UI与业务分离 控制台交互 数据抽象 需求 用户输入字母表示方…