Kotlin Multiplatform ESC/POS Thermal Printing Library
A single unified API for thermal printer discovery, connection, ESC/POS receipt building, and status monitoring β across Android, iOS, JVM/Desktop, JS, and Wasm.
- β Multiplatform β Android, iOS, JVM/Desktop, JS, Wasm
- β Multiple Transports β Bluetooth Classic, BLE, USB, Network TCP, Serial, Virtual
- β ESC/POS Receipt DSL β text styling, alignment, tables, dividers, images, barcodes, QR codes
- β Flow-based Discovery β reactive printer scanning via Kotlin coroutines
- β Status Monitoring β real-time paper out, cover open, error detection
- β Chunked Sending β prevents printer buffer overflow
- β Concurrency Protection β built-in mutex for safe multi-thread printing
- β Preview Rendering β render receipts virtually for UI preview
- β MIT Licensed β free for commercial and personal use
| Platform | Bluetooth Classic | BLE | USB | Network TCP | Status Query |
|---|---|---|---|---|---|
| Android | β | β | β | β | β |
| iOS | β | β | β | β | β |
| JVM/Desktop | β OS serial/queue | β BlueZ helper | β raw USB/serial | β | |
| Web (JS) | β | β | β | β | |
| Wasm | β | β | β | β |
Support depends on printer firmware, OS APIs, browser capabilities, and hardware transport. See Transport Support for details.
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven {
url = uri("https://raw.githubusercontent.com/ringga-dev/kmp-printer/maven-repo")
}
}
}// build.gradle.kts
kotlin {
sourceSets {
commonMain.dependencies {
implementation("io.github.ringga-dev:kmp_printer:2.3.3")
}
}
}Maven users:
<!-- pom.xml --> <dependency> <groupId>io.github.ringga-dev</groupId> <artifactId>kmp_printer</artifactId> <version>2.3.3</version> <!-- sync-version --> </dependency>Available on Maven Central β no extra repository needed.
import ngga.ring.printer.KmpPrinter
import ngga.ring.printer.model.PrinterConfig
val printer = KmpPrinter()
val config = PrinterConfig(
name = "Receipt Printer",
connectionType = "NETWORK",
address = "192.168.1.50",
port = 9100,
characterPerLine = 32,
paperWidth = 58
)
printer.print(config) {
alignCenter()
bold(true)
line("β COFFEE SHOP")
bold(false)
divider()
tableRow(listOf("Americano", "2", "6.00"), listOf(2, 1, 1))
tableRow(listOf("Latte", "1", "4.50"), listOf(2, 1, 1))
divider()
line("Total: $10.50", align = "RIGHT")
feed(1)
qrCodeNative("https://example.com", center = true)
feed(3)
cut()
}.collect { status -> println(status) }printer.print(config) {
setCharset(PrinterCharset.USA_EUROPE)
alignCenter()
image(myBitmap, center = true)
feed(2)
bold(true)
fontSize(2)
line("HEADER")
fontSize(1)
bold(false)
divider('=')
table(listOf("Item", "Qty", "Price"), listOf(2, 1, 1))
tableRow(listOf("Product 1", "3", "9.99"), listOf(2, 1, 1))
barcode("123456789012", type = BarcodeType.EAN13)
feed(2)
cut()
}printer.discovery("NETWORK") { log ->
println("Scanning: $log")
}.collect { devices ->
devices.forEach { device ->
println("Found: ${device.name} at ${device.address}:${device.port}")
}
}printer.monitorStatus(config, intervalMs = 2000).collect { status ->
when {
status.isPaperOut -> sendAlert("π’ Printer kehabisan kertas!")
status.isCoverOpen -> sendAlert("π Cover printer terbuka!")
!status.isOnline -> sendAlert("β οΈ Printer offline!")
}
}// Recommended for new code β avoids hardcoded strings
val networkConfig = PrinterConfig(
name = "Kitchen Printer",
connection = PrinterConnection.NETWORK,
profile = PrinterProfile.MM58,
address = "192.168.1.50"
)
val bleConfig = PrinterConfig(
name = "Portable Printer",
connection = PrinterConnection.BLE,
address = "00:11:22:33:44:55",
profile = PrinterProfile.MM80
)printer.print(config) {
printQuality(PrintQuality.Dark)
line("High density thermal output")
cut()
}| Document | Description |
|---|---|
| Transport Support | Platform-by-platform transport compatibility |
| Printer OS Setup | OS-level driver & permission setup (Linux udev, Windows, macOS) |
| API & Migration | Typed configs, profiles, migration from v1 |
| Releasing | How to publish to GitHub Maven & Maven Central |
| GitHub Pages | Online documentation site |
# Build all platforms
./gradlew build
# Run JVM tests
./gradlew :printer:jvmTest
# Compile specific targets
./gradlew :printer:compileKotlinMetadata
./gradlew :printer:compileKotlinJs
./gradlew :printer:compileKotlinWasmJs
./gradlew :printer:compileDebugKotlinAndroid
# Update version in docs after changing LIB_VERSION in gradle.properties
./gradlew syncDocumentationVersionprinter/
βββ src/
β βββ commonMain/ # Shared platform-independent logic
β β βββ model/ # Printer models, configs, enums
β β βββ manager/ # Connection management, discovery
β β βββ usecase/ # Print, discover, diagnose
β β βββ util/ # ESC/POS commands, rendering, preview
β βββ androidMain/ # Android BLE, USB, Network, Bluetooth
β βββ iosMain/ # iOS BLE, Network
β βββ jvmMain/ # Desktop USB, Serial, Network, BlueZ
β βββ jsMain/ # Web Bluetooth, USB, Serial, Network
β βββ wasmJsMain/ # Wasm hardware bridge
βββ androidApp/ # Android sample app
βββ desktopApp/ # JVM Desktop sample app
βββ iosApp/ # iOS sample app
We welcome contributions! Please see CONTRIBUTING.md for guidelines on:
- Code style and PR process
- Platform-specific testing
- How to add new transport support
MIT License β see LICENSE.
Copyright (c) 2026 Ringga. Free to use, modify, and distribute in commercial and non-commercial applications.
Built with β€οΈ and Kotlin Multiplatform β β Star on GitHub