使用 Javascript 打印 ZPL 标签

Print ZPL labels with Javascript

我正在使用此示例来打印标签: https://www.neodynamic.com/articles/How-to-print-raw-Zebra-ZPL-commands-from-Javascript/ 一切正常,除了如果我想每次点击打印超过 1 个标签,它会允许我这样做,例如,如果我使用 for 或 while 循环打印,但每次 for 都会在说打印的警报上移动现在每次都出现 这是最后一部分在我的代码中的样子 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^FD0.50^FS";
        cmds += "^FO50,20^GB530,120,6,B,0"

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


        //Enviar impresion a Zebraimpresora
        cpj.sendToClient()

;

如果您想打印多份,只需将其加倍即可。

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^FD0.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)