neodynamic / js-escpos-builder

JSESCPOSBuilder - ESC/POS Commands Builder for Javascript
MIT License
41 stars 14 forks source link

Can't break the builder, then add Text() in loop, then finish #1

Closed yubinchen18 closed 4 years ago

yubinchen18 commented 4 years ago
        var escposCommands = doc
            .font(escpos.FontFamily.B)
            .size(0, 0);

        for (var i = 0, len = lines.length; i < len; i++) {
            var line = lines[i];
            escposCommands.text(line);
        }

        escposCommands
            .feed(5)
            .cut()
            .generateUInt8Array();

cpj.binaryPrinterCommands = escposCommands;

        //Send print job to printer!
        cpj.sendToClient();

this doesn't work?

neodynamic commented 4 years ago

The code logic should be this one instead

var escpos = Neodynamic.JSESCPOSBuilder;
var doc = new escpos.Document();
doc.font(escpos.FontFamily.B).size(0, 0);
for (var i = 0, len = lines.length; i < len; i++) {
    var line = lines[i];
    doc.text(line);
}
var escposCommands = doc.feed(5).cut().generateUInt8Array();
cpj.binaryPrinterCommands = escposCommands;
//Send print job to printer!
cpj.sendToClient();