how do I send ZPL commands from node js?

0

Best regards to all: Veran I am trying to print a label with the language of zebra, from node js So far it has been possible to connect to the zebra printer (S4M) and print. The problem I have is that it only prints plain text and does not interpret the zebra code. Will someone know if there is a library or something similar that allows me to send the zebra codes to a printer from node js? or a way to do it. Any help or comment will be very much appreciated. This is the source that is carried so far. Thank you :)

     require('node-native-printer/src/windows_printer.js'.setPrinter);

require('./lib.js').your_function();
const printer = require('node-native-printer');
constWindows =require('node-native-printer/src/windows_printer.js')
const lista=printer.listPrinters(constWindows);


console.log(lista);
let printer_name= 'ZDesigner S4M';
printer.setPrinter(printer_name)

function printZebra(filename, options,  printer_name){
    // printer.setPrinter(printer_name)
    // console.log('________________________________________________');
    // printer.printerInfo(printer_name)
    // printer.print(filename,options, printer_name)
    var text = '^XA^LH15,15^FO15,10^BY2^BCN,55,N,N,N^FD[[CODIGO]]^FS^FO100,72^A0,30,23^FD[[CODIGO]]^FS^FO285,15^A0,60,53^FD[[PRECIO]]^FS^FO25,100^A0,24,20^FD[[PRODUCTO]]^FS^XZ'
    printer.printText(text,options, printer_name)//imprime txt

}

printZebra("C:\impresion_zebra.txt", {
    "collate": true,
    "color": true,
    "copies": 1,
    "duplex": "Default",
    "landscape": false,
    "paperSize": "",
}, printer_name);
    
asked by Gustavo Lopez 20.12.2018 в 19:34
source

1 answer

0

I do not know any library in NodeJS that allows this to be done, however I implemented a solution in LabView that could be applied on this occasion. The steps would be the following:

  • Generate a plain text file (txt) with the text to be printed (using the respective Zebra codes).
  • Print this through the windows shell. Share the printer by network and using the NET USE LPT1:<ruta> /PERSISTENT:YES command (check the printer port) send the printout of the file. This is how I made the first successful manual tests.
  • Using the node library node-cmd perform the same steps, do not send the print directly from NodeJS.
  • answered by 21.12.2018 / 15:33
    source