@azarudeen-ahamed/capacitor-printer
v0.1.0
Published
Capacitor plugin for printing to Bluetooth, WiFi, USB and POS handheld printers with ESC/POS support
Maintainers
Readme
@azarudeen-ahamed/capacitor-printer
Multi-printer Capacitor plugin for Ionic/Angular apps. Supports Bluetooth (Classic + BLE), WiFi (TCP/IP), USB, and built-in POS handheld printers (Sunmi, PAX, Newland, iMin) with full ESC/POS command support, multiple paper sizes, barcodes, QR codes, and image printing.
Features
- Multi-printer support: Bluetooth Classic, BLE, WiFi, USB, POS handheld built-in
- ESC/POS encoding: Bold, alignment, font sizes, underline, line feeds, paper cut, cash drawer
- Barcodes: CODE128, EAN-13, EAN-8, UPC-A, UPC-E, CODE39, CODE93, ITF, CODABAR
- QR Codes: Configurable size and error correction (L/M/Q/H)
- Image printing: Base64 images, rasterized for thermal printers
- NV Graphics: Store images in printer flash memory
- Paper sizes: 44mm, 58mm, 76mm, 80mm (configurable characters per line)
- POS handheld: Auto-detect Sunmi, PAX, Newland, iMin built-in printers
- Encoding: UTF-8, GBK, CP437, CP850
Installation
npm install @azarudeen-ahamed/capacitor-printer
npx cap syncAndroid Permissions
Add to android/app/src/main/AndroidManifest.xml:
<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" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-feature android:name="android.hardware.usb.host" android:required="false" />iOS Setup
Add to ios/App/Info.plist:
<key>NSBluetoothAlwaysUsageDescription</key>
<string>This app uses Bluetooth to connect to printers</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>This app uses Bluetooth to connect to printers</string>
<key>UISupportedExternalAccessoryProtocols</key>
<array>
<string>com.zebra.rawport</string>
<string>com.epson.escpos</string>
<string>com.bixolon.protocol</string>
</array>Basic Usage
import { Printer } from '@azarudeen-ahamed/capacitor-printer';
// Discover Bluetooth printers
const { devices } = await Printer.discoverBluetoothPrinters();
// Connect to a Bluetooth printer
await Printer.connect({
type: 'bluetooth-classic',
address: devices[0].address,
});
// Print text
await Printer.printText({ text: 'Hello World', bold: true, align: 'center' });
// Print a full receipt
await Printer.printReceipt({
paperSize: '80mm',
items: [
{ type: 'text', text: 'NEOLYSI PMS', bold: true, align: 'center', fontSize: 2 },
{ type: 'divider' },
{ type: 'text', text: 'Room 101 - Checkout', bold: true },
{ type: 'divider' },
{ type: 'text', text: 'Room Charge $150.00' },
{ type: 'text', text: 'Mini Bar $25.00' },
{ type: 'text', text: 'Laundry $15.00' },
{ type: 'divider' },
{ type: 'text', text: 'TOTAL: $190.00', bold: true, align: 'right' },
{ type: 'barcode', barcode: { type: 'CODE128', content: 'INV-001' } },
{ type: 'qr', qrCode: { content: 'https://neolysi.com/inv/001', size: 6 } },
{ type: 'text', text: 'Thank you!', align: 'center' },
],
cutPaper: true,
});
// Cut paper
await Printer.cutPaper();
// Disconnect
await Printer.disconnect();Connection Types
// Bluetooth Classic
await Printer.connect({ type: 'bluetooth-classic', address: '00:11:22:33:44:55' });
// Bluetooth Low Energy
await Printer.connect({ type: 'ble', address: 'AA:BB:CC:DD:EE:FF' });
// WiFi (TCP/IP)
await Printer.connect({ type: 'wifi', ip: '192.168.1.100', port: 9100 });
// USB
await Printer.connect({ type: 'usb', vendorId: 1046, productId: 20482 });
// Built-in POS (auto-detect Sunmi/PAX/Newland/iMin)
await Printer.connect({ type: 'pos-builtin' });API Reference
Discovery
| Method | Returns | Description |
|--------|---------|-------------|
| discoverBluetoothPrinters() | PrinterDevice[] | List paired BT devices |
| discoverWifiPrinters() | WifiPrinterDevice[] | Scan subnet for TCP printers |
| discoverUsbPrinters() | UsbPrinterDevice[] | List connected USB printers |
Connection
| Method | Description |
|--------|-------------|
| connect(options) | Connect to a printer by type |
| disconnect() | Disconnect current printer |
| isConnected() | Check connection status |
| getPosPrinterStatus() | Get POS handheld printer info |
Printing
| Method | Description |
|--------|-------------|
| printText(options) | Print a single line of text |
| printReceipt(options) | Print a full receipt with items |
| printRaw(options) | Send raw ESC/POS bytes |
| printImage(options) | Print a base64 image |
| printBarcode(options) | Print a barcode |
| printQr(options) | Print a QR code |
Commands
| Method | Description |
|--------|-------------|
| setPaperSize(options) | Set paper width |
| getPaperSize() | Get current paper size |
| setBold(options) | Toggle bold |
| setAlignment(options) | Set text alignment |
| setTextSize(options) | Set text size |
| lineFeed(options) | Feed paper lines |
| cutPaper() | Cut paper (full) |
| openCashDrawer() | Open cash drawer |
| resetPrinter() | Reset printer |
| storeNvImage(options) | Store image in printer NV memory |
| printNvImage(options) | Print stored NV image |
Paper Sizes
| Key | Width | Characters | Max Dots |
|-----|-------|-----------|----------|
| 44mm | 44mm | 24 | 320 |
| 58mm | 58mm | 32 | 384 |
| 76mm | 76mm | 42 | 546 |
| 80mm | 80mm | 48 | 576 |
Supported POS Handheld Devices
- Sunmi: V1, V2, V2s, V2 Pro, T1, T2, D2, D2s, L2, P2, P2 Pro, SP1
- PAX: A920, A80, A77, S920, S90, D180, D210
- Newland: N900, N910, N950, MT90, MT65
- iMin: M1, M2, M3, P1, D1, T1
Encoding Support
| Encoding | Use Case |
|----------|----------|
| UTF-8 | Modern printers with Unicode support |
| GBK | Chinese printers (Sunmi, PAX POS) |
| CP437 | Legacy ESC/POS printers (default) |
| CP850 | Western European printers |
License
MIT
