Skip to content

OutputStreams

Marco Antonio edited this page Dec 4, 2021 · 3 revisions

Builtin OutputStreams

Escpos-coffee have some builtin OutputStreams to send data to the printer:

PrinterOutputStream

Problably it is the most common used outputstream on escpos-coffee, its because its simplicity of usage and it uses standard java resources. Supply outputStream to any installed printer.

Platform Compatibility
Linux yes
Windows yes
Mac yes
Android no

Listing all installed printers

String[] printServicesNames = PrinterOutputStream.getListPrintServicesNames();
for (String printServiceName : printServicesNames) {
    System.out.println(printServiceName);
}

Using the PrinterOutputStream

escpos = new EscPos(new PrinterOutputStream("your printer name obtained above"));
escpos.writeLF("Hello PrinterOutputStream");;
// do not forget to close...
escpos.close();

get source-code like this

TcpIpOutputStream

If you have one Ethernet printer, you can use TcpIpOutputStream

Platform Compatibility
Linux yes
Windows yes
Mac yes
Android yes

Using the TcpIpOutputStream

TcpIpOutputStream outputStream = new TcpIpOutputStream(host,port)
EscPos escpos = new EscPos(outputStream);
escpos.writeLF("Hello TcpIpOutputStream");
escpos.close();

get source-code like this

Other OutputStreams found on samples

For now can be used, but are still considered beta version:

UsbStream

Offers usb OutputStream.

Platform Compatibility
Linux yes
Windows yes
Mac unknown
Android no

complete project here

SerialStream

Offers usb Serial port OutputStream.

Platform Compatibility
Linux yes
Windows yes
Mac unknown
Android no

complete project here