26
loading...
This website collects cookies to deliver better user experience
window.print()
method, and that's it. But that approach has some drawbacks:Download the SDK: https://download.epson-biz.com/modules/pos/index.php?page=single_soft&cid=6679&scat=57&pcat=52
Unzip the SDK and copy the epos-2.17.0.js
file to your project under the public
folder.
Reference the script
As the SDK is not designed to be used on strict mode, to be included in a React app, need to be referenced on public/index.html
file.
connect
function opens the connection with the printer and keeps it open for further printing.let ePosDev = new window.epson.ePOSDevice();
ePosDevice.current = ePosDev;
ePosDev.connect(printerIPAddress, printerPort, (data) => {
if (data === "OK") {
ePosDev.createDevice(
"local_printer",
ePosDev.DEVICE_TYPE_PRINTER,
{ crypto: true, buffer: false },
(devobj, retcode) => {
if (retcode === "OK") {
printer.current = devobj;
setConnectionStatus(STATUS_CONNECTED);
} else {
throw retcode;
}
}
);
} else {
throw data;
}
});
print
function does it:const print = (text) => {
let prn = printer.current;
if (!prn) {
alert("Not connected to printer");
return;
}
prn.addText(text);
prn.addFeedLine(5);
prn.addCut(prn.CUT_FEED);
prn.send();
};
addText
, addFeedLine
, etc.) to print and use the printer capabilities. Here you can check the available SDK methods /ReceiptDesigner/index.en.html
print()
method.