SkillAgentSearch skills...

ThermalPrinterESCPOS

Thermal Printer ESC/POS Library For Android.

Install / Use

/learn @EmHaseeb/ThermalPrinterESCPOS

README

License: Apache 2.0

ThermalPrinter ESC/POS Android library

Useful library to help Android developers to print with (Bluetooth, WIFI, Network, USB) thermal printers ESC/POS.

❤️ Supporting

⭐ Star this repository to support this library. You can contribute to increase the visibility of this library 🙂

❤️ Whats New in

  • CashTray/CashBox/CashDrawer Support Added.
  • Encoding Improvemed.
  • CashTray related function are mentioned below:
        new Thread(new Runnable() {
            public void run() {
                try {
                    EscPosPrinter printer = new EscPosPrinter(new TcpConnection(ip, port), 203, 65f, 42);
                    printer.openCashBox();
                    printer.disconnectPrinter();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
EscPosPrinter printer = null;
        try {
            printer = new EscPosPrinter(BluetoothPrintersConnections.selectFirstPaired(), 203, 48f, 32);
            printer.printFormattedTextAndOpenCashBox(
                    "[C]<img>" + PrinterTextParserImg.bitmapToHexadecimalString(printer, getApplicationContext().getResources().getDrawableForDensity(R.drawable.testp, DisplayMetrics.DENSITY_MEDIUM)) + "</img>\n" +
                            "[L]\n" +
                            "[C]<u><font size='big'>ORDER N°1125</font></u>\n[L]\n" +
                            "[L] _________________________________________\n" +
                            "[L] Description [R]Amount\n[L]\n" +
                            "[L] <b>Beef Burger [R]10.00\n" +
                            "[L] Sprite-200ml [R]3.00\n" +
                            "[L] _________________________________________\n" +
                            "[L] TOTAL [R]13.00 BD\n" +
                            "[L] Total Vat Collected [R]1.00 BD\n" +
                            "[L]\n" +
                            "[L] _________________________________________\n" +
                            "[L]\n" +
                            "[C]<font size='tall'>Customer Info</font>\n" +
                            "[L] EM Haseeb\n" +
                            "[L] 14 Streets\n" +
                            "[L] Cantt, LHR\n" +
                            "[L] Tel : +923040017916\n" +
                            "[L]\n" +
                            "[L] <barcode type='ean13' height='10'>831254784551</barcode>\n[L]\n" +
                            "[L] <qrcode>http://github.com/EmHaseeb/</qrcode>\n[L]\n[L]\n[L]\n",5
            );
            printer.disconnectPrinter();
        } catch (EscPosConnectionException | EscPosParserException | EscPosEncodingException | EscPosBarcodeException e) {
            e.printStackTrace();
        }

Table of contents

Android version

Minimum SDK Version 16 Android 4.1 and above are supported.

Tested printers

  1. EPSON TM-T88VI (121): SERIAL, USB, ETHERNET (Tested over Network/Ethernet 📶)
  2. EPSON TM-T20 SERIES (Tested over USB 🔌)
  3. Sewoo LK-P41 (Bluetooth Printer)
  4. OmniLink® TM-m50 POS Thermal Receipt Printer (Tested over Wifi)

Test it !

To test this library, it's very simple.

  • Create a directory and open a terminal inside
  • Run git clone https://github.com/EmHaseeb/ThermalPrinterESCPOS.git .
  • Open the directory with Android Studio
  • Test it

Installation

Step 1. Add the JitPack repository to your build file. Add it in your root /build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency in /app/build.gradle :

dependencies {
    ...
    implementation 'com.github.EmHaseeb:ThermalPrinterESCPOS:1.0.2'
}

Bluetooth

Bluetooth permission

Be sure to have <uses-permission android:name="android.permission.BLUETOOTH" />, <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />, <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />, <uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> in your AndroidManifest.xml.

Also, you have to check the bluetooth permission in your app like this :

if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.S && ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH) != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.BLUETOOTH}, MainActivity.PERMISSION_BLUETOOTH);
} else if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.S && ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_ADMIN) != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.BLUETOOTH_ADMIN}, MainActivity.PERMISSION_BLUETOOTH_ADMIN);
} else if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S && ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.BLUETOOTH_CONNECT}, MainActivity.PERMISSION_BLUETOOTH_CONNECT);
} else if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S && ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED) {
    ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.BLUETOOTH_SCAN}, MainActivity.PERMISSION_BLUETOOTH_SCAN);
} else {
    // Your code HERE
}

Bluetooth code example

The code below is an example to write in your activity :

EscPosPrinter printer = null;
            try {
                printer = new EscPosPrinter(BluetoothPrintersConnections.selectFirstPaired(), 203, 48f, 32);
                printer.printFormattedTextAndCut(
                        "[C]<img>" + PrinterTextParserImg.bitmapToHexadecimalString(printer, getApplicationContext().getResources().getDrawableForDensity(R.drawable.testp, DisplayMetrics.DENSITY_MEDIUM)) + "</img>\n" +
                                "[L]\n" +
                                "[C]<u><font size='big'>ORDER N°1125</font></u>\n[L]\n" +
                                "[L] _________________________________________\n" +
                                "[L] Description [R]Amount\n[L]\n" +
                                "[L] <b>Beef Burger [R]10.00\n" +
                                "[L] Sprite-200ml [R]3.00\n" +
                                "[L] _________________________________________\n" +
                                "[L] TOTAL [R]13.00 BD\n" +
                                "[L] Total Vat Collected [R]1.00 BD\n" +
                                "[L]\n" +
                                "[L] _________________________________________\n" +
                                "[L]\n" +
                                "[C]<font size='tall'>Customer Info</font>\n" +
                                "[L] EM Haseeb\n" +
                                "[L] 14 Streets\n" +
                                "[L] Cantt, LHR\n" +
                                "[L] Tel : +923040017916\n" +
                                "[L]\n" +
                                "[L] <barcode type='ean13' height='10'>831254784551</barcode>\n[L]\n" +
                                "[L] <qrcode>http://github.com/EmHaseeb/</qrcode>\n[L]\n[L]\n[L]\n"
                );
                printer.disconnectPrinter();
            } catch (EscPosConnectionException e) {
                e.printStackTrace();
            }

TCP

TCP permission

Be sure to have <uses-permission android:name="android.permission.INTERNET"/> in your AndroidMenifest.xml.

TCP code example

The code below is an example to write in your activity :

  new Thread(new Runnable() {
            public void run() {
                try {
                    EscPosPrinter printer = new EscPosPrinter(new TcpConnection(ip, port), 203, 65f, 42);
                    printer.printFormattedTextAndCut(
                            "[C]<img>" + PrinterTextParserImg.bitmapToHexadecimalString(printer, getApplicationContext().getResources().getDrawab

Related Skills

View on GitHub
GitHub Stars30
CategoryDevelopment
Updated3mo ago
Forks12

Languages

Java

Security Score

92/100

Audited on Dec 12, 2025

No findings