Silent Printing on Electron
I have an old dot matrix printer (Epson LX-800) set up on an LPT port on a Windows 10 machine. I can print fine from Windows, but it uses graphics mode, takes forever, and the quality is not that great. I've always wanted to be able to print to this printer using the built in fonts (both draft and NLQ) but nothing I could find on Windows really supports it in an elegant way. So the other day I was updating my Ape Apps Launcher application, and decided that I would implement my own solution for printing to this printer, so that I could at least use it the way I want to in my own applications.
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:
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/print
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!
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";
fs.writeFileSync(tmpFileName,printString,"utf8");
var child = require('child_process').exec;
child('print /d:' + printer + ' "' + tmpFileName + '"');
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/print
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!
bastecklein
Developer
Member Since
September 2nd, 2017