TSC打印机打印条形码和二维码,applet实现方式

新逸网络 1.5K 0

applet方式实现TSC打印条码功能。

applet方式打印实现复杂,最大的优点就是不用注册 dll 控件,不过现在最新的浏览器已经不支持java了,不建议使用,以下内容仅供参考。

 

说明:

1、applet使用复杂,不建议使用。

2、需要浏览器支持java,也就是支持jre即可。

3、js的实现方式见另一篇文章。

4、TSC applet和js打印测试包(包含打印机驱动、打印插件、applet和js调试代码),https://www.xinac.com/article/223.html

5、有问题请尽量发邮件,10513276@qq.com

    JButton button;
    String image_path = "/images/img.jpg";
    private String title = "xxxxxxxxxxxxxx";
 
    public void init() {
        ImageIcon image = new ImageIcon(this.getClass().getResource(this.image_path));
        button = new JButton(image);
        button.addActionListener(this);
        this.getContentPane().add(button);
    }
 
    @Override
    public void actionPerformed(ActionEvent arg0) {
        String code = getParameter("bar_code");
        if (code != null && code != "") {
            this.print(code);
        }
    }
 
    public void print(String code) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                // TscLibDll.INSTANCE.about();
                TscLibDll.INSTANCE.openport("TSC TTP-244 Pro");
                TscLibDll.INSTANCE.setup("60", "40", "5", "10", "0", "2", "0");
                TscLibDll.INSTANCE.sendcommand("SET TEAR ON");
                TscLibDll.INSTANCE.clearbuffer();
                TscLibDll.INSTANCE.sendcommand("QRCODE 100,200,L,7,M,0,[2,7],'N123456' ");
                // TscLibDll.INSTANCE.sendcommand("PUTPCX 550,10,\"UL.PCX\"");
                TscLibDll.INSTANCE.barcode("70", "140", "128", "90", "0", "0", "2", "2", code);
                TscLibDll.INSTANCE.windowsfont(55, 20, 48, 0, 2, 1, "Arial", title);
                TscLibDll.INSTANCE.windowsfont(120, 240, 32, 0, 2, 0, "Arial", code);
                // TscLibDll.INSTANCE.windowsfont(400, 200, 48, 90, 3, 1, "Arial", "DEG 90");
                // TscLibDll.INSTANCE.windowsfont(400, 200, 48, 180, 3, 1, "Arial", "DEG 180");
                // TscLibDll.INSTANCE.windowsfont(400, 200, 48, 270, 3, 1, "Arial", "DEG 270");
                TscLibDll.INSTANCE.printlabel("1", "1");
                TscLibDll.INSTANCE.closeport();
            }
        });
    }

applet调用方式需要将.dll文件放到项目目录,也可以放到jdk目录

有时客户端还是不能打印,还需做以下修改:

D:\Program Files (x86)\Java\jre7\lib\security\java.security(这个文件是在用户端需要修改的,因为想要打印的人是用户端)

在grant中加一行:

permission java.security.AllPermission;

如果还是不能打印,可以试试改成下边这样:

    AccessController.doPrivileged(new PrivilegedAction<String>() {
 
        @Override
        public String run() {
 
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    TscLibDll.INSTANCE.openport("TSC TTP-244 Pro");
                    // do something
                }
            });
            return null;
        }
 
    });

 

————————————————
版权声明:本文为CSDN博主「星河漫步」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/jinqilin721/article/details/88865854

————————————————
版权声明:本文为CSDN博主「星河漫步」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/jinqilin721/article/details/88865854

发表评论 取消回复
表情 图片 链接 代码

分享