Capacitor plugin for thermal printing via USB and Bluetooth
npm install @ruhiverse/thermal-printer-pluginCapacitor plugin for thermal printing via USB and Bluetooth connections. Supports ESC/POS formatted text printing.
``bash`
npm install @ruhiverse/thermal-printer-plugin
npx cap sync
`typescript`
import { ThermalPrinter } from '@ruhiverse/thermal-printer-plugin';
`typescript
import { ThermalPrinter } from '@ruhiverse/thermal-printer-plugin';
// Print text using USB connection
await ThermalPrinter.printByUsb({
textToPrint: '[C]Hello World\n[C]This is a test print',
});
`
`typescript
import { ThermalPrinter } from '@ruhiverse/thermal-printer-plugin';
// Print text using Bluetooth connection
await ThermalPrinter.printByBluetooth({
textToPrint: '[C]Hello World\n[C]This is a test print',
});
`
The plugin supports ESC/POS formatting commands. Here are some examples:
`typescript
// Center align text
'[C]Centered Text';
// Bold text
'Bold Text';
// Multiple lines
'Line 1\nLine 2\nLine 3';
// Combined formatting
'[C]Centered Bold Text\n[L]Left aligned text';
`
Common formatting tags:
- [C] - Center align[L]
- - Left align[R]
- - Right aligntext
- - Boldtext
- - Underlinetext
- - Big font
You can list available printers and select one by its address (Bluetooth) or name (USB).
`typescript
// List Bluetooth printers
const { printers } = await ThermalPrinter.listBluetoothPrinters();
console.log('Available Bluetooth printers:', printers);
// Print to a specific Bluetooth printer
await ThermalPrinter.printByBluetooth({
textToPrint: '[C]Hello from specific printer',
address: printers[0].address, // MAC address
});
// List USB printers
const { printers: usbPrinters } = await ThermalPrinter.listUsbPrinters();
console.log('Available USB printers:', usbPrinters);
// Print to a specific USB printer
await ThermalPrinter.printByUsb({
textToPrint: '[C]Hello from specific USB printer',
name: usbPrinters[0].name, // Device name
});
`
Print text using USB connection.
| Param | Type | Description |
| --------------- | ------------- | ----------------------------------- |
| printObject | PrintObject | Object containing options for print |
Returns: Promise
Print text using Bluetooth connection.
| Param | Type | Description |
| --------------- | ------------- | ----------------------------------- |
| printObject | PrintObject | Object containing options for print |
Returns: Promise
Returns a list of paired Bluetooth printers.
Returns: Promise<{ printers: { name: string, address: string }[] }>
Returns a list of connected USB printers.
Returns: Promise<{ printers: { name: string, address: string }[] }>
| Prop | Type | Description |
| --------------- | -------- | ---------------------------------------------------------------- |
| textToPrint | string | Text to print. Supports ESC/POS formatting commands. |string
| address | | (Optional) Bluetooth MAC address of the printer (for Bluetooth). |string
| name | | (Optional) USB device name of the printer (for USB). |
- ✅ Android (USB & Bluetooth)
- ✅ iOS (USB & Bluetooth - basic implementation)
- ❌ Web (not supported)
The plugin automatically requests the following permissions:
- BLUETOOTHBLUETOOTH_ADMIN
- BLUETOOTH_CONNECT
- (Android 12+)BLUETOOTH_SCAN
- (Android 12+)USB_PERMISSION
-
1. Connect your thermal printer via USB
2. Grant USB permission when prompted
3. The plugin will automatically detect and connect to the printer
1. Pair your thermal printer with the device via Bluetooth settings
2. The plugin will automatically find and connect to paired printers
Add the following to your app's Info.plist:
`xml`
Note: iOS implementation may require additional setup based on your printer model. USB printing on iOS requires MFi (Made for iPhone) certification.
1. Link the plugin locally:
`bash`
cd /Users/apple/Desktop/ionic/workspace/plugin/thermal-printer-plugin
npm link
2. In your Ionic/Capacitor project (e.g., milkwala project):
`bash`
cd /path/to/milkwala/project
npm link @ruhiverse/thermal-printer-plugin
npx cap sync
3. Build and test:
`bashFor Android
npx cap run android
$3
You can also install directly from the local path:
`bash
cd /path/to/milkwala/project
npm install /Users/apple/Desktop/ionic/workspace/plugin/thermal-printer-plugin
npx cap sync
`Publishing to npm
1. Login to npm (if not already logged in):
`bash
npm login
Use your ruhiverse npm account credentials
`2. Build the plugin:
`bash
npm run build
`3. Publish to npm:
`bash
npm publish --access public
`4. After publishing, install in your project:
`bash
npm install @ruhiverse/thermal-printer-plugin
npx cap sync
`Development
$3
`bash
npm run build
`$3
`bash
npm run lint
`$3
`bash
npm run fmt
``MIT
Paresh Gami
Company: Ruhiverse
Website: https://ruhiverse.com