After searching the net for a good way to print silently with raw text and command codes to an old dot matrix printer, I decided to just roll a simple solution by saving all of the commands for the printer in a plain text file, and then printing it silently using the built in Windows 'print' command. The solution ends up working pretty good, and the code is dead simple:
var fs = require('fs');The 'printer' variable can be either lpt1/lpt2 or a network printer share. See the reference for the print command here:
var printString = "whatever text you need to print with optional ascii commands";
var printer = "lpt1";
var tmpFileName ="c:\tmp.txt";
var child = require('child_process').exec;
child('print /d:' + printer + ' "' + tmpFileName + '"');
I haven't tried it, but I'm sure something similar can be hashed out for Mac/Linux using the lpr command.
Hopefully this helps somebody. I also posted this information on a Stack Overflow post here. I literally spent a day trying to get a more 'native' Electron/nodejs way for this to work, but it turns out sticking to the basics was the easiest way to accomplish it. And for those of you using the Ape Apps Launcher on Windows, you can benefit from the fruits of my work by enabling RAW/Text printing in the settings:
That is, if there is anybody out there besides me who still rocks an old dot matrix printer from the late 80's. But it's built into the Launcher now regardless, and comes pre-loaded with just about the entire ESC/P command set, so it should work on most dot matrix and probably receipt printers, from the 80's to today. I might use this new code to release an invoicing app for shops who still use these printers. We'll see!