Reputation: 3083
My query is I have a printer connected to the ethernet and I am able to print to that printer using the IP address of the printer but the issue is the printer stops the moment the lines given for printing ends and hence the paper is stuck in the printer.
My Code:
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();
}
Upvotes: 2
Views: 3649
Reputation: 1016
I am not able to print with your code after making socket connection with printer.
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();
}
Upvotes: 0
Reputation: 3346
Just add a \f
at the end of the line.
oStream.println("\n\n\n\f");
It's for form feed / new page
Upvotes: 3