簡體   English   中英

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

[英]Print in Android using a printer with specific IP address

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

只需在行末添加\\f

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

用於換頁/新頁面

與打印機建立套接字連接后,我無法使用您的代碼進行打印。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM