Introduction
πΏ Introduction to papermint
Section titled βπΏ Introduction to papermintβpapermint is a fast, multi-vendor, type-safe thermal receipt printing engine designed from first principles in Rust.
The Problem with Legacy Thermal Printing
Section titled βThe Problem with Legacy Thermal PrintingβFor decades, developers building Point-of-Sale (POS) systems, kitchen ticket routers, self-checkout kiosks, and mobile receipts relied on fragile legacy libraries in Python or JavaScript (such as python-escpos or node-thermal-printer).
These legacy libraries share fundamental architectural flaws:
- Ad-hoc byte concatenation: Functions directly append raw hex escape bytes into an array buffer. If you need to switch printer vendors (e.g. from Epson to Star Micronics), you have to rewrite your formatting logic.
- Jagged, broken tables: They calculate character padding using
str.length. When printing international characters (Japanese, Chinese, Arabic, emojis, or accents), table columns distort and misalign because they fail to account for monospace terminal cell widths. - Kernel driver crashes: USB communication in legacy libraries often requires
pyusband kernel driver detachment (detach_kernel_driver(0)), which destabilizes operating system USB hubs and requires root (sudo) privileges. - Printer buffer overflows: Sending large images without chunking exceeds the 4KBβ64KB volatile RAM limits of thermal printers, causing printers to freeze, spit out random characters, or crash.
The Papermint Solution
Section titled βThe Papermint Solutionβpapermint redesigns thermal printing around an Intermediate Representation (IR):
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ 1. Layout Engine (Receipt Builder) ββ Produces an abstract stream of instructions βββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ β Vec<Command> βΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ 2. Dialect Encoders (EscPos / StarPRNT) ββ Translates commands into vendor wire bytes on demand βββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββ β Wire Bytes (Vec<u8>) βΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ 3. Driverless Transports ββ TCP Port 9100 | Raw USB (nusb) | RS-232 | In-Memory Mock ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββCore Highlights
Section titled βCore Highlightsβ- Universal Portability: Write your receipt logic once. Render it on Epson ESC/POS, StarPRNT, or an in-memory mock sink for testing.
- Typographic Monospace Precision: Monospace column mathematics powered by Unicode Standard Annex #11 (East Asian Width) with synchronized multiline row wrapping.
- Driverless USB: Communicates directly with operating system USB bulk endpoints via
nusbwithout vendor drivers orsudo. - Universal Ecosystem: Use
papermintin pure Rust, in Node.js/TypeScript via N-API (papermint), over HTTP viapapermintd, in React Native/Expo (expo-papermint), in Flutter (dart:ffi), or in native iOS (Swift), Android (Kotlin), and Kotlin Multiplatform (KMP).