Connecting Android to Bluetooth Thermal Printers
Mobile point-of-sale and logistics apps often need to print receipts on compact thermal printers. Instead of requiring third-party Android apps to write custom Bluetooth code for every printer brand, Thermal Printer Service was built in Kotlin as a native Android PrintService with a PrinterDiscoverySession.
This design hooks directly into the standard Android print dialog. Whenever a user taps Print in any Android application, the document is sent to the service as a temporary PDF file, allowing our background engine to handle scaling, formatting, and Bluetooth transmission automatically.

Converting PDF Pages into Thermal Dot Rasters
- 58 mm printable width
- 432 dots
- 80 mm printable width
- 576 dots
- Resolution
- 203 DPI
- Maximum write chunk
- 1,024 bytes
When a print job arrives, Android's PdfRenderer converts each PDF page into a high-density bitmap. Because standard document sizes do not match narrow thermal receipt paper, the service automatically trims unused whitespace, centers the text, applies custom top/bottom padding, and resizes the bitmap to the printer head width (432 dots for 58 mm rolls or 576 dots for 80 mm rolls at standard 203 DPI).
The adjusted bitmap is then transformed into a clean binary monochrome image, where every black pixel represents a heated dot on the receipt paper.
Generating ESC/POS Commands and Managing Profiles
- Android Document
- Temporary PDF File
- PdfRenderer Bitmap
- Whitespace Trim and Scale
- Monochrome Conversion
- 24-Dot ESC/POS Raster
- Bluetooth Chunked Write
Thermal receipt printers do not understand complex font files; they only print black-and-white dots driven by low-level ESC/POS byte commands. The app converts the monochrome bitmap into 24-dot ESC/POS raster byte arrays in memory, organizing the lines into manageable chunks for transmission.
To support different printer models in the field, configurations are saved locally using SharedPreferences and JSON. A clean RecyclerView list allows operators to easily save and switch between printer profiles, setting Bluetooth address, paper width, density scale, auto-cut, and margin offsets.
Handling Bluetooth Connections and Background Jobs
- Check Bluetooth hardware availability, power state, and Android 12 or newer runtime permissions.
- Load the selected printer profile and temporary PDF payload.
- Open an RFCOMM SPP socket with a 4-step retry strategy using 0 ms, 200 ms, 500 ms, and 1,000 ms backoff delays.
- Process printing in a background single-thread executor with CancellationToken support to keep the Android UI smooth.
- Stream ESC/POS data in chunks up to 1,024 bytes and close sockets cleanly when done or canceled.
By separating document rendering, ESC/POS byte encoding, and Bluetooth connection management into distinct components, Thermal Printer Service provides a smooth and dependable receipt printing experience for everyday Android workflows.