Receipt Printer SDK
@cutos/device-receipt-printer is a JavaScript library that provides a unified interface for accessing and controlling printers that support the Receipt command set. Developers can use this interface to send and receive data, configure printer parameters, and handle printer events.
Installation
npm install @cutos/device-receipt-printer
Import dependencies
import {DeviceReceiptPrinter} from '@cutos/device-receipt-printer';
DeviceReceiptPrinter
Constructor, create receipt printer device instance
let devReceiptPrinter = new DeviceReceiptPrinter();
Example:
devReceiptPrinter = new DeviceReceiptPrinter();
DeviceReceiptPrinter.init
Receipt Printer device initialization
devReceiptPrinter.init(callback);
- callback: Callback function
Example:
devReceiptPrinter.init((result, error) => {
if (!error) {
console.log('init ReceiptPrinter', result)
} else {
console.log(error)
}
});
- Return response example:
"Driver device-receipt-printer loaded"
DeviceReceiptPrinter.connect
Connect Receipt Printer
devReceiptPrinter.connect(path, callback);
- path: Device port
- callback: Callback function
Example:
devReceiptPrinter.connect('/ttyS1', (response) => {
console.log(response)
})
- Return response example:
{
"status": true,
"msg": "already connected"
}
DeviceReceiptPrinter.print
Print Text
devReceiptPrinter.print(text, callback);
- text: Print text
- callback: Callback function
Example:
devReceiptPrinter.print('test result', (response) => {
console.log(response)
})
- Return response example:
{
"status": true,
"msg": "print success"
}
DeviceReceiptPrinter.printQrcode
Print Qrcode
devReceiptPrinter.printQrcode(text, callback);
- text: Text for Qrcode
- callback: Callback function
Example:
devReceiptPrinter.printQrcode('hello cutos', (response) => {
console.log(response)
})
- Return response example:
{
"status": true,
"msg": "print qrcode success"
}
DeviceReceiptPrinter.setAlign
Alignment setting.
setAlign(align, callback)
- align: Alignment setting,Valid values: 'left', 'center', 'right'
- callback: Callback function
Example:
devReceiptPrinter.setAlign('left', (response) => {
console.log(response)
})
- Return response example:
{
"status": true,
"msg":"set align success"
}
DeviceReceiptPrinter.setFontSize
Print font size setting
devReceiptPrinter.setFontSize(width, height, callback)
- width:Font width(1-7)
- height:Font height(1-7)
- callback:Callback function
Example:
devReceiptPrinter.setFontSize(2, 2, (response) => {
console.log(response)
})
- Return response example:
{
"status": true,
"msg":"set fontSize success"
}
DeviceReceiptPrinter.feed
Print blank line
devReceiptPrinter.feed(lines, callback)
- lines:Blank line count,Blank lines have the same height as text lines(1-255).
- callback:Callback function
Example:
devReceiptPrinter.feed(1, (response) => {
console.log(response)
})
- Return response example:
{
"status": true,
"msg":"feed success"
}