Depends on what you're trying to print exactly, but you could try electron print.
You could see if it works in your system with a quick "helloworld" snippet:
const printer = require('electron-print');
app.on('ready', function() {
printer.print("Text sent to printer.")
});
Another thing you could try is using electron's PrinterInfo[] object. You can get a JSON array with the printers as follows:
contents.getPrinters()
For each printer it will return an "options" configuration object (docs) which you can use to print using:
contents.print([options])
That would print the current webpage. You might even be able to do silent printing by opening the print contents into a hidden window and using:
webContents.print({silent: true, printBackground: false, deviceName: ''})
Really depends on what you want to do. There's a bunch of config params you can play with.
EDIT AFTER COMMENT:
Seems like electron-print wraps node-print, which supports sending printing commands directly to the printer using printDirect(), this comes from their raw printing example:
cmds = 'your printer commands, guess you have the printer spec'
printer.printDirect({data: cmds
, type: 'RAW'
, success:function(jobID: any){
console.log("sent to printer with ID: "+jobID);
}
, error:function(err: any){console.log(err);}
});
Not sure if electron-print provides a wrapper for this function too, but you could easily add it yourself if you think it's worth a try.
EDIT 2:
Just found this: https://www.neodynamic.com/articles/How-to-print-raw-ESC-POS-commands-from-Javascript