使用Java打印Zebra ZM400

Ray*_*ond 3 java zpl-ii zebra-printers

我的打印机是Zebra ZM400标签打印机,它连接到网络中的一台(通过USB连接).

我想通过网络和打印标签从我的电脑发送命令到标签打印机.

如何从网络连接该打印机和从Java应用程序打印标签?

我知道我要使用ZPL语言,但我不知道如何连接并向标签打印机发送命令.

可能吗?我在谷歌浏览但我找不到任何示例代码.

编辑

我使用了norbi771的方法..但是当它发送命令时,只是空白出来..

我的标签尺寸为3.25"x 3.75"..

这是我的标签示例代码..但没有任何结果..

public class TestLabelPrinter {

    /**
     * @param args
     */
    public static void printLabel(String label, String company, String docDate)  {
        try {
            FileOutputStream os = new FileOutputStream("\\\\192.168.42.57\\zd");
            PrintStream ps = new PrintStream(os); 
            String commands = "^XA" +
                              "^LH30,30" +
                              "^F020,10^AD^FDZEBRA^FS" + 
                              "F020,60^B3^FDAAA001^FS" + 
                              "^XZ";     

            ps.println(commands);
            ps.print("\f");
            ps.close();
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        printLabel("label 12345", "Company name", "2013-05-10 12:45");
        System.out.println("Successful..");
    }
Run Code Online (Sandbox Code Playgroud)

nor*_*771 5

也许不是最好的答案,但我最近这样做了.我用Windows将打印机连接到PC.然后我分享了打印机.然后这个共享打印机我通过简单的命令映射到LPT1(所有这一切都可以在一台PC上完成):

net use \\pcname\sharedprinter LPT1:
Run Code Online (Sandbox Code Playgroud)

从现在开始,这个LPT1端口也就是您可以写入的文件.现在我只是在JAVA中将数据写入该文件,它工作正常.我知道它不是很优雅,但适合我,让我使用一台PC之间共享的标签打印机

    public class EplPrint1 {
            private final String port;
            public EplPrint1(String port) {
                    this.port = port;
            }
            public void printLabel(String label, String company, String docDate) throws FileNotFoundException {
                    FileOutputStream os = new FileOutputStream(port);
                    PrintStream ps = new PrintStream(os);
                    String commands = "N\n"
                            +  "A1,1,0,1,1,1,N,\""+asciiNormalize(company)+"\"\n"
                            + "A1,20,0,1,1,1,N,\""+asciiNormalize("Entry date")+": " + docDate+"\"\n"
                            + "B1,40,0,1,3,2,80,B,\""+label+"\"\n"
                            + "P1,1\n";     

                    ps.println(commands);
                    ps.print("\f");
                    ps.close();
            }

            public static void main(String[] argv) throws FileNotFoundException {
                    //EplPrint1 p = new EplPrint1("d:\\tmp\\eplcommands.txt");
                    EplPrint1 p = new EplPrint1("LPT1");
                    //p.printLabel("23535.A.33.B.233445");  
                    p.printLabel("label 12345", "Company name", "2013-05-10 12:45");
            }
    }
Run Code Online (Sandbox Code Playgroud)

提供的示例用于EPL打印,但ZPL应以相同的方式工作.