3

enter image description hereAnyone knows how to set-up a USB printer for node js. I m not able to configure the interface for it . Here is my code

enter code here const ThermalPrinter = require("../node-thermal-printer").printer;
                const Types = require("../node-thermal-printer").types;
                const electron = typeof process !== 'undefined' && process.versions && 
                                  !!process.versions.electron;

                async function testConnection () { 

                let printer = new ThermalPrinter({
                type: 'star',                                    
                interface: "Gold" //name of the printer
                });
                printer.print("hi");
                let isConnected = await printer.isPrinterConnected() 
                console.log("Printer connected:", isConnected);
                }
                 testConnection();
Rahul Mongia
  • 31
  • 1
  • 4
  • According to the npm description article, `interface: "Gold"` is written as `interface: "printer:Gold"`, isn't it? [Interface options](https://www.npmjs.com/package/node-thermal-printer#interface-options) – kunif Feb 03 '21 at 04:06
  • After setting this it is saying cannot able to find driver set for it. Even I tried setting the interface as "printer: Gold" still got stuck into the driver set – Rahul Mongia Feb 03 '21 at 04:33
  • As in the same explanation, is it necessary to set using [node-printer](https://www.npmjs.com/package/printer) or [electron-printer](https://www.npmjs.com/package/electron-printer)? – kunif Feb 03 '21 at 04:49
  • yes, it is as I am using node-thermal-printer. – Rahul Mongia Feb 03 '21 at 06:03
  • In the description of node-thermal-printer, it seems that it is necessary to specify `driver:` in the definition of `let printer = new ThermalPrinter` or do `setPrinterDriver()` in addition, so please add it and try it. – kunif Feb 03 '21 at 06:49
  • what path should I add as a driver while using a USB printer? – Rahul Mongia Feb 03 '21 at 09:35
  • For the time being, try something with node-printer or electron-printer alone, and if you can do it, try using it from node-thermal-printer. [How to print a docx file to a printer using Node.js](https://stackoverflow.com/q/50817153/9014308), [is it possible to print an image with node.js?](https://stackoverflow.com/q/23437804/9014308), [Use Node js to to print data to thermal printer](https://stackoverflow.com/q/59225919/9014308), [Receipt thermal printer in Electron](https://stackoverflow.com/q/53254089/9014308) – kunif Feb 03 '21 at 10:08
  • I have read and tried all of the above I am able to print using a Lan printer but for a USB printer, it's not working. – Rahul Mongia Feb 03 '21 at 11:31
  • After that, try these forks [devarthurribeiro/thermal-printer](https://github.com/devarthurribeiro/thermal-printer), or replace them with [song940/node-escpos](https://github.com/song940/node-escpos), including node-thermal-printer. – kunif Feb 03 '21 at 11:44
  • Yes I tried both of them also still got stuck in USB printer.. – Rahul Mongia Feb 04 '21 at 13:27
  • There is an example that you can print with npm-escpos, so why not set the printer to serial port mode and install the corresponding device driver? [Create receipt with escpos package and Serial port](https://stackoverflow.com/q/65575304/9014308), [Epson thermal printer status from NodeJS with ESC/POS](https://stackoverflow.com/q/62176249/9014308) – kunif Feb 04 '21 at 15:26

2 Answers2

3

The error that jumps out at me is in your interface. if you use a usb port I advise you to start by making a print sharing and then to configure your node-termal-printer file by modifying the value "interface"

  1. first you do a printer sharing enter image description here

  2. you modify the value "interface" indicating the path and the shared printer

         `interface: '//localhost/printer',`
    
0

install your printer and simply test on windows that it works, remember to install the manufacturer's drivers,

then you simply indicate the port you used (in interface: 'com1', or 'com3' ...)

example

 let printer = new ThermalPrinter({
  type: PrinterTypes.EPSON,
  interface: '//./COM3'
});