Home > Enterprise >  Print ZPL labels with Javascript
Print ZPL labels with Javascript

Time:12-07

Im using this example to print labels: https://www.neodynamic.com/articles/How-to-print-raw-Zebra-ZPL-commands-from-Javascript/ everything its working fine,except that if i want to print more than 1 label per click it dosent allow me to do it, for example if Im using a for or while cycle to print,but everytime the for moves on the alert that Says Print now appears everytime this is how that last part looks like in my code n = 0;

while (n < 2) {
          n   ;

        var cmds =  "^XA";

        cmds  = "^FO480,21^ARN,1,90^FD/^FS";  
        cmds  = "^FO62,36^AUN,90,100^FDEL ZAPATON^FS";
        cmds  = "^FO0,135^ARN,60,14^FDDama 4^FS";
        cmds  = "^FO0,200^ARN,60,40^FD^FS";
        cmds  = "^BY2,2,100";
        cmds  = "^FO10,270^BC^FDE0430601926027^FS";
        cmds  = "^FO410,273^AUN,100,75^FD$350.50^FS";
        cmds  = "^FO50,20^GB530,120,6,B,0"

        cmds  = "^XZ";
        cpj.printerCommands = cmds;


        //Enviar impresion a Zebraimpresora
        cpj.sendToClient()

;

CodePudding user response:

If you want to print multiple copies just double it up.

var zplStr =
`^XA
^FO480,21^ARN,1,90^FD/^FS
^FO62,36^AUN,90,100^FDEL ZAPATON^FS
^FO0,135^ARN,60,14^FDDama 4^FS
^FO0,200^ARN,60,40^FD^FS
^BY2,2,100
^FO10,270^BC^FDE0430601926027^FS
^FO410,273^AUN,100,75^FD$350.50^FS
^FO50,20^GB530,120,6,B,0
^XZ`;

const numOfCopies = 2;
var cmds = new Array(numOfCopies).fill(zplStr).join("\n");
console.log(cmds)
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related