Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reliance on electron-printer/node-printer #209

Open
mattkrins opened this issue Jul 26, 2022 · 3 comments
Open

Reliance on electron-printer/node-printer #209

mattkrins opened this issue Jul 26, 2022 · 3 comments

Comments

@mattkrins
Copy link

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?

@Wolyo
Copy link

Wolyo commented Jul 26, 2022

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 fixed it with this

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"

@mattkrins
Copy link
Author

mattkrins commented Jul 26, 2022

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.

@SimantoR
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants