使用具有特定IP地址的打印机在Android中打印

问题描述:

我的查询是我有一台打印机连接到以太网,并且能够使用打印机的IP地址打印到该打印机,但问题是打印机停止用于打印的线条结束,因此纸张卡在打印机中。使用具有特定IP地址的打印机在Android中打印

我的代码:

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(); 
} 

只需在该行的末尾添加一个\f

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

这对换/新页

我不能做与 打印机socket连接后,你的代码进行打印。

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(); 
}