2016-09-19 172 views
2

我的查詢是我有一臺打印機連接到以太網,並且能夠使用打印機的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(); 
} 

回答

3

只需在該行的末尾添加一個\f

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

這對換/新頁

0

我不能做與 打印機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(); 
}