sunmi-printer-plugin
v1.0.0
Published
Cordova plugin wrapper for Sunmi PrinterX SDK on Android
Maintainers
Readme
Sunmi Printer Cordova Plugin
Cordova plugin wrapper for Sunmi PrinterX SDK (com.sunmi:printerx) on Android.
Features
- Printer discovery and basic info query
- Ticket printing (
lineApi) - Label printing (
canvasApi) - ESC/POS and TSPL command passthrough
- Cash drawer control
- Auto-injected JS bridge (
SunmiPrinterSDK)
Install
Local install from current workspace:
cordova plugin add ./plugin-srcInstall from npm:
cordova plugin add sunmi-printer-pluginJS Entry
After plugin installation, SunmiPrinterSDK is injected by Cordova automatically.
No manual <script src="js/sunmi-bridge.js"> include is required.
Required Initialization
Call initPrinter before any print, command, or cash drawer API:
SunmiPrinterSDK.initPrinter(
function () {
console.log("printer ready");
},
function (err) {
console.error("initPrinter failed:", err);
}
);If not initialized, native side returns:
打印机未初始化,请先调用 initPrinter
API Overview
Printer info
initPrinter(success, error)getPrinterInfo(success, error)
Ticket printing
initLine(style, success, error)printText(content, style, success, error)addText(content, style, success, error)printTexts(texts, weights, styles, success, error)printBarCode(data, style, success, error)printQrCode(data, style, success, error)printBitmap(base64, style, success, error)printDividingLine(style, success, error)autoOut(success, error)enableTransMode(enable, success, error)printTrans(success, error)
Label printing
initCanvas(style, success, error)renderArea(style, success, error)renderText(content, style, success, error)renderBarCode(data, style, success, error)renderQrCode(data, style, success, error)renderBitmap(base64, style, success, error)printCanvas(count, success, error)
Command passthrough
sendEscCommand(hexData, success, error)sendTsplCommand(data, success, error)
Cash drawer
open(success, error)isOpen(success, error)
PrinterX Version Strategy
Default pinned version:
com.sunmi:printerx:1.0.18
Override from Gradle properties if needed:
- Property name:
SUNMI_PRINTERX_VERSION - Example:
SUNMI_PRINTERX_VERSION=1.0.18 - Project example file:
gradle.properties.example - For Cordova Android builds, place this key in
platforms/android/gradle.properties
The plugin resolves version in build-extras.gradle:
def sunmiPrinterxVersion = project.hasProperty("SUNMI_PRINTERX_VERSION")
? SUNMI_PRINTERX_VERSION
: "1.0.18"Notes
- This plugin targets Android only.
- Keep
plugin-srcas the source of truth.plugins/andplatforms/are generated artifacts.
Release Checklist
Before publishing to npm:
cd plugin-src
npm test
npm run pack:checkRecommended before Android test submission:
cordova build android