So I wanna document my process to run node-thermal-printer:
MacOS: 10.15.2
Node: 12.8.1
Electron: 7.1.9
node-thermal-printer: From pull request #135
node-printer: https://github.com/thiagoelg/node-printer
(you can clone it and change name to 'printer' to replace node-printer)
electron-rebuild: 1.8.8
Once all the packages are added via npm, run ./node_modules/.bin/electron-rebuild
to rebuild all native modules for your current electron version. That should do the trick. I also have sqlite3
and fsevents
as my native modules. All gets compiled alright and runs pretty nicely.
my code const ThermalPrinter = require("node-thermal-printer").printer;
const PrinterTypes = require("node-thermal-printer").types;
const prr = require("printer");
const electron =
typeof process !== "undefined" &&
process.versions &&
!!process.versions.electron;
let printer = new ThermalPrinter({
type: PrinterTypes.EPSON,
interface: "printer:My Printer",
driver: prr
});
const ThermalPrinter = require("./node_modules/node-thermal-printer").printer;
const Types = require("./node_modules/node-thermal-printer").types;
async function testConnection () {
let printer = new ThermalPrinter({
type: Types.EPSON,
interface: 'my interface'
});
let isConnected = await printer.isPrinterConnected();
console.log("Printer connected:", isConnected);
}
testConnection();
const ThermalPrinter = require("node-thermal-printer").printer;
const PrinterTypes = require("node-thermal-printer").types;
const printer = require("printer");
const electron = typeof process !== 'undefined' && process.versions && !!process.versions.electron;
console.log('default printer name: ' + (printer.getDefaultPrinterName() || 'is not defined on your computer'));
let print = new ThermalPrinter({
type: PrinterTypes.STAR,
interface: 'printer:Star TSP100 Cutter (TSP143)',
characterSet: 'SLOVENIA',
removeSpecialCharacters: false,
driver: require(electron ? 'electron-printer' : 'printer'),
options:{
timeout: 5000
}
});
async function printing() {
let isConnected = await print.isPrinterConnected();
let execute = await print.execute();
let raw = await print.raw(Buffer.from("Hello world"));
print.print("Hello World");
print.println("Hello World");
print.cut();
print.partialCut();
print.beep();
print.upsideDown(true);
print.setCharacterSet("SLOVENIA");
}
printing();
// Set printer drive - default set on init
Hi I have an Epson thermal printer, It's a USB printer, I am using node js as backend in my application,I want to integrate this pckg and use to print receipt in my application,
I saw your package and you have mentioned only how to connect with tcp connection printer , not with USB connection printer ,
please please help me on this
Hi i have epson thermal printer with Electron 16.0.4 this library work well on linux with lp0 usb but not working on windows 7
let printer = new ThermalPrinter({
type: PrinterTypes.EPSON, // Printer type: 'star' or 'epson'
interface: process.platform === 'linux' ? '/dev/usb/lp0' : 'printer:' + data.printer_name,
options: { // Additional options
timeout: 5000 // Connection timeout (ms) [applicable only for network printers] - default: 3000
}
})
it's wrap inside function....