@capvision/printer-pos
v1.1.0
Published
Library that offers easy API to communicate with point-of-sales printers, by serial way (usb), TCP/IP (wifi) and bluetooth.
Readme
Node POS
Library that offers easy API to communicate with point-of-sales printers, by serial way (usb), TCP/IP (wifi) and bluetooth.
Usage
import { AbstractAdapter, SerialAdapter, USBAdapter, listPrinters, Printer } from "@capvision/printer-pos";
const printers = await listPrinters();
const selectedPrinter = printers[0];
let adapter: AbstractAdapter;
if(selectedPrinter.type === "USB") {
adapter = new USBAdapter({
vendorId: selectedPrinter.vendorId,
productId: selectedPrinter.productId,
});
}
else {
adapter = new SerialAdapter({
path: selectedPrinter.path,
});
}
// or directly adapter = new *Adapter(selectedPrinter);
const printer = new Printer(adapter);
await printer.open();
printer.setDefaultStyle({
align: "left",
bold: false,
underline: false,
double: false,
font: "a",
});
await printer
.text("=== Printing Test ===\n", { bold: true, underline: true })
.text("Hello, this is a printing test.\n", { align: "center" })
.text("We thank you for using our POS solution !\n\n", { font: "b" })
.cut()
.flush();
await printer.close();Even easier :
import { AdapterFactory, listPrinters, Printer } from "@capvision/printer-pos";
const printers = await listPrinters();
const selectedPrinter = printers[0];
const adapter = AdapterFactory.create(selectedPrinter);
const printer = new Printer(adapter);Notes
USB devices can work with Serial Port, or native USB.
Bluetooth devices almost always work Serial Port.
