Open mattkrins opened 2 years ago
let printer = new ThermalPrinter({
type: PrinterTypes.EPSON,
interface: 'printer:myprinter',
characterSet: 'ISO8859_2_LATIN2',
removeSpecialCharacters: false,
lineCharacter: "=",
options: {
timeout: 5000
},
driver: require(electron ? '@thiagoelg/node-printer' : 'printer')
});
I'm using it this way, I just had to do a few extra steps because when I installed the node-printer library I couldn't find it in the node modules folder.
I used it with that "node-printer" because if I used another one, the driver couldn't find two methods that I don't remember exactly which ones, I think they were getPrinter() and directPrint(), don't believe me but it was something like that, so I used "@thiagoelg /node-printer" because it did work, but when executing the Electron project it gave me an error, so I had to install "Desktop development with C++".
I don't know or believe that what I did is the best practices but it solved the problem for me.
After installing the VS I did this
npm install --save-dev electron-rebuild npm i @thiagoelg/node-printer electron-rebuild
I tried until "electron-rebuild" passed the "node-printer" correctly in the end I got some errors but I didn't pay much attention to them and when I ran the electron project "node-printer" I no longer got the "self error" and I was able to use the "node-thermal"
Thanks for the advice @Wolyo , I tried a similar method but got errors when trying to package the project which i couldn't resolve, but the dev env worked fine.
I found another workaround today which is going to suit me better: On the host running node-thermal-printer share the local printer like you would to the network, but only set permissions for the local user, then for the ThermalPrinter interface just use '//localhost/LocalPrinterName'. No extra library required this way, but it would still be nice to not need workarounds.
Maybe we could build a new C++ Node.JS library for local printers across the 3 platforms. Printer are ancient at this point and finding reference code wouldn't be too hard. I am looking to do things over the network primarily but testing has been a pain since I use a wired one. thiagoelg/node-printer
seems to be fine, but a more maintained one would be nice.
This library works brilliantly for printing to networked printers, however I would like to print to a local printer too, but due to the reliance on electron-printer/node-printer this is not possible as these libraries are dead/broken and pull requests are ignored. Is it possible to print locally without electron-printer/node-printer?