@simplymobile/capacitor-printer-usb
v8.0.0
Published
Capacitor USB printer plugin
Readme
@simplymobile/capacitor-printer-usb
Capacitor plugin for sending raw data to USB printers (devices with interface class
USB_CLASS_PRINTER). Android-only; on iOS and web every method is unimplemented.
USB permission is requested at runtime through the Android system dialog the first time a printer is used. No manifest permissions are required.
Install
npm install @simplymobile/capacitor-printer-usb
npx cap syncAPI
scan()
scan() => Promise<{ printers: UsbPrinterDevice[]; }>Scan for connected USB printers (devices whose interface class is USB_CLASS_PRINTER).
Returns: Promise<{ printers: UsbPrinterDevice[]; }>
print(...)
print(options: { printerName: string; text: string; }) => Promise<{ message: string; }>Send raw text to a USB printer identified by its product name.
Requests USB permission (system dialog) if it has not been granted yet. The returned promise resolves once the data has been transferred, and rejects if permission is denied or an error occurs.
| Param | Type |
| ------------- | --------------------------------------------------- |
| options | { printerName: string; text: string; } |
Returns: Promise<{ message: string; }>
test(...)
test(options: { printerName: string; }) => Promise<{ message: string; }>Send a predefined test command (~WC) to the given USB printer.
| Param | Type |
| ------------- | ------------------------------------- |
| options | { printerName: string; } |
Returns: Promise<{ message: string; }>
Interfaces
UsbPrinterDevice
| Prop | Type | Description |
| ---------------------- | --------------------------- | --------------------------------------------------------------------- |
| productName | string | null | USB product name reported by the device. |
| manufacturerName | string | null | USB manufacturer name reported by the device. |
| deviceId | number | Android USB device id. |
| serialNumber | string | null | USB serial number (may be null if not readable without permission). |
| vendorId | number | USB vendor id. |
