1.0.6 • Published 3 years ago

thermal-printer-cordova-plugin v1.0.6

Weekly downloads
14
License
Apache-2.0
Repository
github
Last release
3 years ago

Cordova Plugin for Thermal Printer's

npm version npm downloads


This plugin is a wrapper for the Android library for ESC/POS Thermal Printer.

Install

Cordova

$ cordova plugin add thermal-printer-cordova-plugin

Ionic

$ ionic cordova plugin add thermal-printer-cordova-plugin

Capacitor

$ npm install thermal-printer-cordova-plugin
$ npx cap sync

Don't forget to add BLUETOOTH and INTERNET (for TCP) permissions and for USB printers the android.hardware.usb.host feature to the AndroidManifest.xml.

<uses-feature android:name="android.hardware.usb.host" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.INTERNET" />

listPrinters(data, successCallback, errorCallback)

List available printers

ParamTypeDescription
dataObjectData object
data.type"bluetooth" | "usb"Type of list: bluetooth or usb
successCallbackfunctionResult on success
errorCallbackfunctionResult on failure

printFormattedText(data, successCallback, errorCallback)

Print a formatted text and feed paper

See: https://github.com/DantSu/ESCPOS-ThermalPrinter-Android#formatted-text--syntax-guide

ParamTypeDescription
dataArray.<Object>Data object
data.type"bluetooth" | "tcp" | "usb"List all bluetooth or usb printers
data.idstring | numberID of printer to find (Bluetooth: address, TCP: Use address + port instead, USB: deviceId)
data.addressstringIf type is "tcp" then the IP Address of the printer
data.portnumberIf type is "tcp" then the Port of the printer
data.mmFeedPapernumberMillimeter distance feed paper at the end
data.dotsFeedPapernumberDistance feed paper at the end
data.textstringFormatted text to be printed
successCallbackfunctionResult on success
errorCallbackfunctionResult on failure

printFormattedTextAndCut(data, successCallback, errorCallback)

Print a formatted text, feed paper and cut the paper

See: https://github.com/DantSu/ESCPOS-ThermalPrinter-Android#formatted-text--syntax-guide

ParamTypeDescription
dataArray.<Object>Data object
data.type"bluetooth" | "tcp" | "usb"List all bluetooth or usb printers
data.idstring | numberID of printer to find (Bluetooth: address, TCP: Use address + port instead, USB: deviceId)
data.addressstringIf type is "tcp" then the IP Address of the printer
data.portnumberIf type is "tcp" then the Port of the printer
data.mmFeedPapernumberMillimeter distance feed paper at the end
data.dotsFeedPapernumberDistance feed paper at the end
data.textstringFormatted text to be printed
successCallbackfunctionResult on success
errorCallbackfunctionResult on failure

getEncoding(data, successCallback, errorCallback)

Get the printer encoding when available

ParamTypeDescription
dataArray.<Object>Data object
data.type"bluetooth" | "tcp" | "usb"List all bluetooth or usb printers
data.idstring | numberID of printer to find (Bluetooth: address, TCP: Use address + port instead, USB: deviceId)
data.addressstringIf type is "tcp" then the IP Address of the printer
data.portnumberIf type is "tcp" then the Port of the printer
successCallbackfunctionResult on success
errorCallbackfunctionResult on failure

disconnectPrinter(data, successCallback, errorCallback)

Close the connection with the printer

ParamTypeDescription
dataArray.<Object>Data object
data.type"bluetooth" | "tcp" | "usb"List all bluetooth or usb printers
data.idstring | numberID of printer to find (Bluetooth: address, TCP: Use address + port instead, USB: deviceId)
data.addressstringIf type is "tcp" then the IP Address of the printer
data.portnumberIf type is "tcp" then the Port of the printer
successCallbackfunctionResult on success
errorCallbackfunctionResult on failure

requestPermissions(data, successCallback, errorCallback)

Request permissions for USB printers

ParamTypeDescription
dataArray.<Object>Data object
data.type"bluetooth" | "tcp" | "usb"List all bluetooth or usb printers
data.idstring | numberID of printer to find (Bluetooth: address, TCP: Use address + port instead, USB: deviceId)
data.addressstringIf type is "tcp" then the IP Address of the printer
data.portnumberIf type is "tcp" then the Port of the printer
successCallbackfunctionResult on success
errorCallbackfunctionResult on failure

bitmapToHexadecimalString(data, successCallback, errorCallback)

Convert Drawable instance to a hexadecimal string of the image data

ParamTypeDescription
dataArray.<Object>Data object
data.type"bluetooth" | "tcp" | "usb"List all bluetooth or usb printers
data.idstring | numberID of printer to find (Bluetooth: address, TCP: Use address + port instead, USB: deviceId)
data.addressstringIf type is "tcp" then the IP Address of the printer
data.portnumberIf type is "tcp" then the Port of the printer
data.base64stringBase64 encoded picture string to convert
successCallbackfunctionResult on success
errorCallbackfunctionResult on failure