Java调用TSC条码打印机接口打印条码和二维码

型号:TSC TTP-244 PRO、

java后台调试代码(连接好打印机后可直接打印,用于直接调试):

import java.io.UnsupportedEncodingException;

import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.Native;

public class TscMain {
    public interface TscLibDll extends StdCallLibrary {
        TscLibDll INSTANCE = (TscLibDll) Native.loadLibrary("TSCLIB", TscLibDll.class);
        int about();
        int openport(String pirnterName);
        int closeport();
        int sendcommand(String printerCommand);
        int setup(String width, String height, String speed, String density, String sensor, String vertical, String offset);
        int downloadpcx(String filename, String image_name);
        int barcode(String x, String y, String type, String height, String readable, String rotation, String narrow, String wide, String code);
        int printerfont(String x, String y, String fonttype, String rotation, String xmul, String ymul, String text);
        int clearbuffer();
        int printlabel(String set, String copy);
        int formfeed();
        int nobackfeed();
        int windowsfont(int x, int y, int fontheight, int rotation, int fontstyle, int fontunderline, String szFaceName, String content);
    }

    public static void main(String[] args) throws UnsupportedEncodingException {
        System.setProperty("jna.encoding", "GBK");// 支持中文
        // TscLibDll.INSTANCE.about();
        TscLibDll.INSTANCE.openport("TSC TTP-244 Pro");
        // TscLibDll.INSTANCE.downloadpcx("C:\\UL.PCX", "UL.PCX");// 打印图片时需要先下载到设备
        // TscLibDll.INSTANCE.sendcommand("REM ***** This is a test by JAVA. *****");
        TscLibDll.INSTANCE.setup("60", "40", "5", "15", "0", "2", "0");
        TscLibDll.INSTANCE.sendcommand("SET TEAR ON");
        TscLibDll.INSTANCE.clearbuffer();
        String command = "QRCODE 300,70,L,6,A,0,M2,S3,\"123456\"";// 打印二维码
        TscLibDll.INSTANCE.sendcommand(command);
        // TscLibDll.INSTANCE.sendcommand("PUTPCX 550,10,\"UL.PCX\"");// 图片位置
        // TscLibDll.INSTANCE.printerfont("100", "50", "TSS24.BF2", "0", "1", "1", "Technology");
        TscLibDll.INSTANCE.barcode("70", "140", "128", "90", "0", "0", "2", "2", "A123456789");// 打印内容,参数是位置和字体
        TscLibDll.INSTANCE.windowsfont(15, 15, 40, 0, 2, 1, "Arial", "网络科技公司");
        TscLibDll.INSTANCE.windowsfont(30, 90, 32, 0, 2, 0, "Arial", "--- 研发部");
        TscLibDll.INSTANCE.windowsfont(120, 240, 32, 0, 2, 0, "Arial", "A123456789");
        TscLibDll.INSTANCE.printlabel("1", "1");
        TscLibDll.INSTANCE.closeport();
    }
}

如何能够在线操作打印机呢?还想传递参数,同时打印条码和二维码?这里有两个解决方案。

1、使用java applet,再通过java后台调用dll打印。(此方法实现较复杂,有兴趣的可以到http://www.xinac.com/front/article/4253.html查看)

2、直接在页面上使用JS打印二维码。

        <script type="text/javascript">
            var TSCObj = new ActiveXObject("TSCActiveX.TSCLIB");
            TSCObj.ActiveXopenport("TSC TTP-244 Pro");
            TSCObj.ActiveXsetup("60", "40", "5", "12", "0", "2", "0");
            TSCObj.ActiveXsendcommand("SET TEAR ON");
            TSCObj.ActiveXclearbuffer();
            TSCObj.ActiveXwindowsfont(230, 310, 48, 180, 2, 0, "Arial", "固定资产标识卡");
            TSCObj.ActiveXwindowsfont(500, 305, 48, 180, 2, 1, "Arial", "                                          ");
            TSCObj.ActiveXwindowsfont(450, 250, 30, 180, 2, 0, "Arial", "资产名称:测试资产");
            TSCObj.ActiveXwindowsfont(450, 220, 30, 180, 2, 0, "Arial", "资产编号:20171012100003");
            TSCObj.ActiveXwindowsfont(450, 190, 30, 180, 2, 0, "Arial", "使用部门:研发中心");
            TSCObj.ActiveXwindowsfont(450, 160, 30, 180, 2, 0, "Arial", "产品规格:TEST");
            TSCObj.ActiveXwindowsfont(450, 130, 30, 180, 2, 0, "Arial", "购置日期:2017-12-05");
            TSCObj.ActiveXbarcode("450", "90", "128", "60", "1", "180", "2", "2", "20171012100003");
            // TSCObj.ActiveXsendcommand("QRCODE 10,15,L,5,A,0,M2,S3,\"20171012100003\"");
            TSCObj.ActiveXsendcommand("QRCODE 12,10,L,3,A,0,M2,S3,\"http://qr.xxxxx.cn/20171012100003\"");
            TSCObj.ActiveXprintlabel("1", "1");
            TSCObj.ActiveXcloseport();
        </script>
  • 注意:只能用IE下打印,使用前必须先注册驱动;如果不能打印,试试把安全选项全部启动。

附件:http://www.xinac.com/front/article/4253.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值