首页 > 解决方案 > 如何使用打印服务器打印条码?

问题描述

实际上,我想通过打印服务器与打印机连接。我已经编写了一些代码,但我无法连接到该打印服务器的特定打印机。

注意:我可以使用直接 IP 在打印机上连接和打印数据,但由于我们想从打印服务器中选择特定的打印机,我们需要使用公共 IP。

有没有办法从打印服务器连接打印机?如果你能在上面分享一些东西,我将不胜感激。

public static void main (String argv[]) throws Exception
   {
       // The line below illustrates the default port 6101 for `enter code here`mobile printers 9100 is the default port number
       // for desktop and tabletop printers
       try{
           Socket clientSocket=new Socket("172.xx.xx.xxx",6101);//(host,port)
           
           DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
outToServer.writeBytes("^XA");
           outToServer.writeBytes("^FO50,50^ADN,36,20^FD Test Print");
           outToServer.writeBytes("^FS");
           outToServer.writeBytes("^XZ");
           
           clientSocket.close();
       }catch(Exception e){
           e.printStackTrace();
       }
   }

标签: javaprinting

解决方案


推荐阅读