【问题标题】:Print in Android using a printer with specific IP address使用具有特定 IP 地址的打印机在 Android 中打印
【发布时间】:2016-09-19 07:59:31
【问题描述】:

我的问题是我有一台连接到以太网的打印机,我可以使用打印机的 IP 地址打印到该打印机,但问题是打印机在给定的打印行结束时停止,因此纸张是卡在打印机里。

我的代码:

try {
    Socket sock = new Socket("192.168.0.131", 9100);
    PrintWriter oStream = new PrintWriter(sock.getOutputStream());
    oStream.println("HI,test from Android Device");
    oStream.println("\n\n\n");
    oStream.close();
    sock.close();
} catch (UnknownHostException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

【问题讨论】:

  • 有没有办法知道打印是否成功?

标签: java android sockets printing


【解决方案1】:

只需在行尾添加\f

oStream.println("\n\n\n\f");

用于换页/新页面

【讨论】:

    【解决方案2】:

    在建立套接字连接后,我无法使用您的代码打印 打印机。

    try {
          Socket sock = new Socket(ipAddress, 9100);
          PrintWriter oStream = new PrintWriter(sock.getOutputStream());
          oStream.println("HI,test from Android Device");
          oStream.println("\n\n\n");
          oStream.close();
          sock.close();
    } catch (UnknownHostException e) {
               e.printStackTrace();
    } catch (IOException e) {
               e.printStackTrace();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-21
      • 2011-09-11
      • 1970-01-01
      相关资源
      最近更新 更多