因为需要调用打印机封装好的DLL文件,只能在IE下使用ActiveX来调用,直接使用tspl指令来打印。只在前台调用,所以后台什么也不需要,但是客户端需要进行配置,首先要安装打印机驱动,然后注册DLL

本案例相关的dll和整理的文档如下

http://download.csdn.net/detail/u010121228/9861057

在利用ActiveX调用之前,需要注册DLL文件,先把DLL文件夹下的两个 .dll 文件复制到 “C:\windows\system\ ”目录下,

32位系统可直接还用快捷键WIN+R调起并运行 Regsvr32.exe TSCActiveX.dll 指令

64位系统需要运行64位的注册,跳转到当前64位目录下

cd  C:\Windows\SysWOW64

并运行 Regsvr32.exe TSCActiveX.dll 指令,如果不能打印,把dll文件放到 C:\Windows\SysWOW64  目录下再次注册。

JSP实现代码如下

<HTML>
<HEAD>
</HEAD>
<BODY>
<script type='text/javascript' language='javascript'>//********** ActiveX Dll Functions Description **********
//--------------------------------------------------------------------------------------------------------------------------------------------------
//TSCActiveX.TSCLIB.ActiveXabout()
//  Description: Display the DLL version on the screen.
//
//--------------------------------------------------------------------------------------------------------------------------------------------------
//TSCActiveX.TSCLIB.ActiveXopenport(ByVal PrinterName As String)
//  Description: Start the Windows printer spool.
//  Parameter:
//      PrinterName : String, for local printer, please specified the printer driver name.
//                    For network printer, please specified the UNC path and printer name.
//--------------------------------------------------------------------------------------------------------------------------------------------------
//TSCActiveX.TSCLIB.ActiveXdownloadpcx(ByVal Filename As String, ByVal ImageName As String)
//  Description: Download mono PCX graphic files to the printer
//  Parameter:
//      Filename : string; file name (including file retrieval path)
//      ImageName : string, names of files that are to be downloaded in the printer memory (Please use capital letters)
//
//--------------------------------------------------------------------------------------------------------------------------------------------------
//TSCActiveX.TSCLIB.ActiveXsetup(ByVal LabelWidth As String, ByVal LabelHeight As String, ByVal Speed As String, ByVal Density As String, ByVal Sensor As String, ByVal Vertical As String, ByVal Offset As String)
//  Description: Set up label width, label height, print speed, print density, sensor type, gap/black mark vertical distancegap/black mark shift distance.
//  Parameter:
//      LabelWidth : string, sets up label width; unit: mm
//      LabelHeight : string, sets up label height; unit: mm
//      Speed : string, sets up print speed, (selectable print speeds vary on different printer models)
//          1.0: sets print speed at 1.0"/sec
//          1.5: sets print speed at 1.5"/sec
//          2.0: sets print speed at 2.0"/sec
//          3.0: sets print speed at 3.0"/sec
//          4.0: sets print speed at 4.0"/sec
//          6.0: sets print speed at 6.0"/sec
//          8.0: sets print speed at 8.0"/sec
//          10.0: sets print speed at 10.0"/sec
//      Density : string, sets up print density
//          0~15the greater the number, the darker the printing
//      Sensor : string, sets up the sensor type to be used
//          0: signifies that vertical gap sensor is to be used
//          1: signifies that black mark sensor is to be used
//      Vertical : string, sets up vertical gap height of the gap/black mark; unit: mm
//      Offset : string, sets up shift distance of the gap/black mark; unit:: mm; in the case of the average label, set this parameter to be 0.
//
//--------------------------------------------------------------------------------------------------------------------------------------------------
//TSCActiveX.TSCLIB.ActiveXformfeed()
//  Description: Skip to next page (of label); this function is to be used after setup
//  Parameter: None
//
//--------------------------------------------------------------------------------------------------------------------------------------------------
//TSCActiveX.TSCLIB.ActiveXnobackfeed()
//  Description: disable the backfeed function
//  Parameter: None
//
//--------------------------------------------------------------------------------------------------------------------------------------------------
//TSCActiveX.TSCLIB.ActiveXsendcommand(ByVal command As String)
//  Description: Sends built-in commands to the bar code printer
//  Parameter: Refer to TSPL for details
//
//--------------------------------------------------------------------------------------------------------------------------------------------------
//TSCActiveX.TSCLIB.ActiveXclearbuffer()
//  Description: Clear
//  Parameter: None
//
//--------------------------------------------------------------------------------------------------------------------------------------------------
//TSCActiveX.TSCLIB.ActiveXwindowsfont(ByVal X As Long, ByVal Y As Long, ByVal Fontheight As Long, ByVal Rotation As Long, ByVal Fontstyle As Long, ByVal Fontunderline As Long, ByVal FaceName As String, ByVal TextContent As String)
//  Description: Use Windows font to print text.
//  Parameter:
//      X: Integer, the starting point of the text along the X direction, given in points
//      Y: Integer, the starting point of the text along the Y direction, given in points
//      Fontheight : Integer, the font height, given in points.
//      Rotation :Integer, rotation in counter clockwise direction
//          0 -> 0 degree
//          90-> 90 degree
//          180-> 180 degree
//          270-> 270 degree
//      Fontstyle : Integer, font style
//          0-> Normal
//          1-> Italic
//          2-> Bold
//          3-> Bold and Italic
//      Fontunderline : Integer, font with underline
//          0-> Without underline
//          1-> With underline
//      FaceName : String, font type face. Specify the true type font name. For example: Arial, Times new Roman.
//      TextContent : String, text to be printed.
//
//--------------------------------------------------------------------------------------------------------------------------------------------------
//TSCActiveX.TSCLIB.ActiveXbarcode(ByVal X As String, ByVal Y As String, ByVal CodeType As String, ByVal Height As String, ByVal Readable As String, ByVal Rotation As String, ByVal Narrow As String, ByVal Wide As String, ByVal Code As String)
//  Description: Use built-in bar code formats to print
//  Parameter:
//      X: string; the starting point of the bar code along the X direction, given in points (of 200 DPI, 1 point=1/8 mm; of 300 DPI, 1point=1/12 mm)
//      Y: string; the starting point of the bar code along the Y direction, given in points (of 200 DPI, 1 point=1/8 mm; of 300 DPI, 1 point=1/12 mm)
//      CodeType : string
//          128 :       Code 128, switching code subset A, B, C automatically
//          128M :      Code 128, switching code subset A, B, C manually.
//          EAN128 :    Code 128, switching code subset A, B, C automatically
//          25 :        Interleaved 2 of 5
//          25C :       Interleaved 2 of 5 with check digits
//          39 :        Code 39
//          39C :       Code 39 with check digits
//          93 :        Code 93
//          EAN13 :     EAN 13
//          EAN13+2 :  EAN 13 with 2 digits add-on
//          EAN13+5 :  EAN 13 with 5 digits add-on
//          EAN8 :      EAN 8
//          EAN8+2 :   EAN 8 with 2 digits add-on
//          EAN8+5 :   EAN 8 with 5 digits add-on
//          CODA :      Codabar
//          POST :      Postnet
//          UPCA :      UPC-A
//          UPCA+2 :   UPC-A with 2 digits add-on
//          UPCA+5 :   UPC-A with 5 digits add-on
//          UPCE :      UPC-E
//          UPCE+2 :   UPC-E with 2 digits add-on
//          UPCE+5 :   UPC-E with 5 digits add-on
//      Height : string; sets up bar code height, given in points
//      Readable : string, sets up whether to print human recognizable interpretation (text) or not.
//          0: prints no interpretation
//          1: prints interpretation
//      Rotation : string; sets up rotation degrees
//          0:      rotates 0 degree
//          90:     rotates 90 degrees
//          180:    rotates180 degrees
//          270:    rotates 270 degrees
//      Narrow : string; sets up narrow bar ratio, refer to TSPL user//s manual
//      Wide : string; sets up narrow bar ratio, refer to TSPL user//s manual
//      Code : string; bar code content
//
//--------------------------------------------------------------------------------------------------------------------------------------------------
//TSCActiveX.TSCLIB.ActiveXprinterfont(ByVal X As String, ByVal Y As String, ByVal FontName As String, ByVal Rotation As String, ByVal Xmul As String, ByVal Ymul As String, ByVal Content As String)
//  Description: Use printer built-in fonts to print
//  Parameter:
//      X: string; the starting point of text (character string) along the X direction, given in points (of 200 DPI, 1 point=1/8 mm; of 300 DPI, 1 point=1/12 mm)
//      Y: string; the starting point of text (character string) along the Y direction, given in points (of 200 DPI, 1 point=1/8 mm; of 300 DPI, 1 point=1/12 mm)
//  FontName : string; built-in font type name, 12 kinds in sum
//      1: 8*/12 dots
//      2: 12*20 dots
//      3: 16*24 dots
//      4: 24*32 dots
//      5: 32*48 dots
//      TST24.BF2: Traditional Chinese 24*24
//      TST16.BF2: Traditional Chinese 16*16
//      TTT24.BF2: Traditional Chinese 24*24 (Telecommunication Code)
//      TSS24.BF2: Simplified Chinese 24*24
//      TSS16.BF2: Simplified Chinese 16*16
//      K: Japan, Korean font 24*24,
//      L: Japan Korean font 16*16
//  Rotation : string; sets up the rotation degree of the text (character string)
//      0: rotates 0 degree
//      90: rotate 90 degrees
//      180: rotate 180 degrees
//      270: rotate 270 degrees
//  Xmul : string; sets up the magnification rate of text (character string) along the X direction, range: 1~8
//  Ymul : string; sets up the magnification rate of text (character string) along the Y direction, range: 1~8
//  Content : string; prints the content of text (character string)
//
//--------------------------------------------------------------------------------------------------------------------------------------------------
//TSCActiveX.TSCLIB.ActiveXprintlabel(ByVal NumberOfSet As String, ByVal NumberOfCopy As String)
//  Description: Print label content
//  Parameter:
//      NumberOfSet : string; sets up the number of label sets
//      NumberOfCopy : string, sets up the number of print copies//--------------------------------------------------------------------------------------------------------------------------------------------------
//TSCActiveX.TSCLIB.ActiveXcloseport()
//  Description: Close Windows printer spool.
//  Parameter: None//--------------------------------------------------------------------------------------------------------------------------------------------------
//
//********** JAVASCRIPT Example **********
//
//
function printQRcode(){var TSCObj;TSCObj = new ActiveXObject("TSCActiveX.TSCLIB");//打印机使用的dll//TSCObj.ActiveXabout(); // 打印机信息TSCObj.ActiveXopenport ("TSC TTP-342 Pro");//打印机名称,不能写错//TSCObj.ActiveXdownloadpcx ("D:/myeclipseproject/filesManager/trunk/doc/02-参考资料/03-二维码打印机/01-开发帮助/PHP调用范例/TSCActiveX.DLL-PHP-Example/","123.PCX");TSCObj.ActiveXsetup("55","40","4","15","0","2.5","0");//打印机设置//TSCObj.ActiveXsetup("标签宽度","标签高度","打印速度","打印浓度(0-15)","感应器类别字串型,0 表示使用垂直間距感測器(gap sensor), 1 表示使用黑標感測器(black mark senso)","Gap/Black mark垂直间距(mm)","Gap/Black mark偏移距离(mm)");//TSCObj.ActiveXformfeed();//TSCObj.ActiveXnobackfeed();TSCObj.ActiveXsendcommand("DIRECTION 1");  //设置标签方向 ,DIRECTION 1 左上角 (x,y)={0,0};DIRECTION 0 右下角 (x,y)={0,0};TSCObj.ActiveXsendcommand ("SET TEAR ON");TSCObj.ActiveXclearbuffer();//TSCObj.ActiveXsendcommand ("PUTPCX 0,0,\"123.PCX\"");/*1、ActiveXprinterfont采用机器内置编码通常用来打英文。2、ActiveXwindowsfont可以输出汉字,但是必须是系统中存在的字体。TSCObj.ActiveXprinterfont ("a","b","c","d","e","f","g");a:字符串,文字X方向起始点,以点表示。b:字符串,文字Y方向起始点,以点表示。c:內建字型名称,共12种(1: 8*12 dots 2: 12*20 dots 3: 16*24 dots 4: 24*32 dots 5: 32*48 dots TST24.BF2: 繁體中文 24*24 TST16.BF2: 繁體中文 16*16 TTT24.BF2: 繁體中文 24*24 (電信碼) TSS24.BF2: 簡體中文 24*24 TSS16.BF2: 簡體中文 16*16 K: 韓文 24*24 L: 韓文 16*16 )d:字符串,旋转角度e:字符串,X方向放大倍率1-8f:字符串,Y方向放大倍率1-8g:字符串,打印内容ActiveXwindowsfont(a,b,c,d,e,f,g,h)说明:使用Windows TTF字体打印文字。参数:a:整数类型,文字X方向起始点,以点表示。b:整数类型,文字Y方向起始点,以点表示。c:整数类型,字体高度,以点表示。d:整数类型,旋转角度,逆时针方向旋转。0-旋转0°,90-旋转90°,180-旋转180°,270-旋转270°。e:整数类型,字体外形。0:标签;1:斜体;2:粗体;3:粗斜体。f:整数类型,下划线,0:无下划线;1:加下划线。g:字符串类型,字体名称。如:Arial,Times new Roman。h:字符串类型,打印文字内容。*/TSCObj.ActiveXwindowsfont (500, 200, 48, 90, 0, 0, "Arial", "\u7f16\u7801");TSCObj.ActiveXwindowsfont (550, 200, 48, 90, 0, 0, "Arial", "你好啊1");TSCObj.ActiveXwindowsfont (600, 200, 48, 90, 0, 0, "Arial", "你好啊2");//var cmd = 'QRCODE 条码X方向起始点,条码Y方向起始点,纠错级别,二维码高度,A(A和M),旋转角度,M2(分为类型1和类型2),S1 (s1-s8,默认s7),\"1231你好2421341325454353\"';var cmd = 'QRCODE 60,30,H,7,A,0,M2,S1,\"\u7f16\u7801\"';TSCObj.ActiveXsendcommand(cmd);TSCObj.ActiveXprintlabel ("1","1");//(打印份数,每页打印张数)TSCObj.ActiveXclearbuffer();//清除TSCObj.ActiveXcloseport();//关闭打印端口
}
</SCRIPT>
</BODY>
</HTML>

TSC 标签打印机,使用TSPL指令,前端 jsp 调用打印二维码和文本标签的案例相关推荐

  1. NodeJs+VueJs +前端实现批量打印二维码

     第一步 :html 设置DIV,用于存放批量生成的二维码  <div class="x_panel" style="margin:0 auto;display:n ...

  2. JS前端调用TSC打印二维码、条码

    公司让用js调用TSC打印二维码,本人已调试成功,希望大家有所帮助! ActiveX下载地址:ActiveX下载地址! 实现代码:JS前端调用TSC打印二维码实现代码 <HTML> < ...

  3. C#调用TSC条码打印机打印二维码(转)

    #region 调用TSC打印机打印/// <summary>/// 调用TSC打印机打印/// </summary>/// <param name="titl ...

  4. C#调用TSC条码打印机打印二维码

    #region 调用TSC打印机打印/// <summary>/// 调用TSC打印机打印/// </summary>/// <param name="titl ...

  5. uniapp中根据URL链接生成二维码(适用所有Javascript运行环境的前端应用),保存二维码到本地相册。

    推荐一款适用所有Javascript运行环境的二维码生成组件. uQRCode是一款基于Javascript环境开发的二维码生成插件,适用所有Javascript运行环境的前端应用和Node.js应用 ...

  6. 微信支付接口调用之二维码失效时间的设置

    今天解决了测试提交上来的一个bug,说是公司网站调用的二维码接口没有做超时失效处理,这种情况容易导致用户账号登出后,该二维码还是有效的,当用户扫描支付时还是能够支付成功,但是微信支付成功后调用我们配置 ...

  7. canvas前端生成海报、二维码、截取节点生成图片

    前言 在最近的项目中,有一个需求是要保存前端生成的二维码,同时需要在二维码上方显示课程名称或者活动名称,下方显示机构名称 这次前端分为PC管理端和uniapp移动端 PC端计划使用qrcode生成二维 ...

  8. Android在针式打印机上通过ESC/P指令打印二维码

    Android在针式打印机上通过ESC/P指令打印二维码 前言 正文 前言 最近有个需求就是在rk3399上通过usb口打印发票单,各大品牌的针式打印机几乎都没有Android平台的SDK,后查找相关 ...

  9. java与前端实现7种二维码

    OC](java与前端实现7种二维码) 1.项目结构 springboot项目 2.后端 QrcodeController package com.ljs.controller;import com. ...

最新文章

  1. 如何设计恒流源输出电路?
  2. Loj #3111. 「SDOI2019」染色
  3. realme怎么互传_realme真我X7 Pro首发体验:非常轻快,颜值不赖
  4. “冷潮”之后,P2P或更加适合投资
  5. 回馈读者:赠花书一本!
  6. 创建 SSH Keys
  7. docker中更新镜像——基于Prometheus
  8. vue(vue-cli+vue-router)+babel+webpack项目搭建入门 (第一步)
  9. python后端教程_Python学习教程(技术干货):关于前后端分离开发入门
  10. 毕业三年,同学基本都辞职了,大部分人看完很有同感~
  11. struts1.x 标签库
  12. Symfony2Book16:Symfony2内部03-事件调度
  13. linux 监听 ipv6,zabbix 监控 ipv6
  14. 无序列表前小黑点图片替换方法
  15. STM32开发实例 基于STM32单片机的智能快递系统
  16. [每天一个知识点]12-Maven怎么读
  17. 微信自定义菜单与网页授权结合
  18. riak mysql_Riak安装
  19. 简易的C语言判断输入的年份为闰年还是平年
  20. 【25】核心易中期刊推荐——智能控制机器人

热门文章

  1. 全新IT资源内控安全解决方案
  2. flash p2p流媒体服务器系统软件,Flash P2P流媒体服务器系统
  3. 幼儿园stem教育的发展有什么意义
  4. java怪物掉落_我的世界地下城boss打法及掉落物品一览
  5. 用一封邮箱定位对方的位置
  6. 北工大计算机系保研,2022推荐免试:北京工业大学2021年保研夏令营活动方案汇总...
  7. Unity UI xlua 热更:还原塞尔达旷野之息 (持续更新:已补充箭头动效)
  8. XV6 RISC-V 源码阅读报告之进程模型
  9. [AC自动机 模板]
  10. 移动电影院和民族电影达成战略合作,传递正能量