2.1.0 • Published 1 year ago
capacitor-ble-printer2 v2.1.0
capacitor-ble-printer2
Capacitor plugin for Zebra printers with Bluetooth.
Install
npm install capacitor-ble-printer2
npx cap syncAndroid
Add the following to your 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"/>Usage
You can send data in ZPL Zebra
import { ZPLPrinter } from 'capacitor-ble-printer2'
//Bounded Devices
ZPLPrinter.listenPrinters().then(value => {
console.log(value.devices);
});
//Print Text
var printText = "^XA"
+ "^FO20,20^A0N,25,25^FDThis is a ZPL test.^FS"
+ "^XZ";
var printerOpts: PrinterOptions = {
macAddress: macAddressPrinter,
printText: printText
}
ZPLPrinter.print(printerOpts).then(_ => {
console.log("Printer Ok!")
}API
print(...)listenPrinters()openBluetoothSettings()enableBluetooth()getStatusPrinter(...)getZPLFromImage(...)- Interfaces
print(...)
print(options: PrinterOptions) => Promise<any>You can send data in ZPL Zebra Programing Language
| Param | Type |
|---|---|
options | PrinterOptions |
Returns: Promise<any>
listenPrinters()
listenPrinters() => Promise<{ devices: BluetoothDevices[]; }>Discover bonded devices
Returns: Promise<{ devices: BluetoothDevices[]; }>
openBluetoothSettings()
openBluetoothSettings() => Promise<any>Show the Bluetooth settings on the device
Returns: Promise<any>
enableBluetooth()
enableBluetooth() => Promise<any>Enable Bluetooth on the device
Returns: Promise<any>
getStatusPrinter(...)
getStatusPrinter(options: StatusPrinterOptions) => Promise<{ status: string; }>You can get a status response from a connected Zebra printer using
| Param | Type |
|---|---|
options | StatusPrinterOptions |
Returns: Promise<{ status: string; }>
getZPLFromImage(...)
getZPLFromImage(options: ZPLConverterOptions) => Promise<{ zplCode: string; }>Get ZPL equivalent code from the base64 Image string
| Param | Type |
|---|---|
options | ZPLConverterOptions |
Returns: Promise<{ zplCode: string; }>
Interfaces
PrinterOptions
| Prop | Type | Description |
|---|---|---|
macAddress | string | Identifier of the remote device |
printText | string | text to print |
BluetoothDevices
| Prop | Type | Description |
|---|---|---|
name | string | Name of the remote device |
macAddress | string | Identifier of the remote device |
id | string | |
class | string |
StatusPrinterOptions
| Prop | Type | Description |
|---|---|---|
macAddress | string | Identifier of the remote device |
ZPLConverterOptions
| Prop | Type | Description |
|---|---|---|
base64Image | string | base64 Image string |
blacknessPercentage | number | Want to add header/footer ZPL code or not |
addHeaderFooter | boolean | Want to add header/footer ZPL code or not |