0

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()

;

1
  • double it up.... Commented Dec 6, 2021 at 23:44

2 Answers 2

0

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)

Sign up to request clarification or add additional context in comments.

1 Comment

thanks, that works fine, i can now print it multiple times without asking me with that messagebox of printing everytime, but can i have let say an array fill with data like this ["TENIS", "VARIOS", "VARIOS"] inside the zpl code and print it multipletimes without that printing message? before i tried doing that in a for loop and for the zpl code i did concatenation inside the zpl code and it was being filled with that array data. it worked fine, the problem was that i keep geting that print message everytime the for did a loop
0

Add Button in HTML Page

<button onclick="printSticker()">Print Sticker</button>

Add Link in HTML Page

<script src="https://www.zebra.com/content/dam/zebra/zebra_com/software/en/application/javascript/BrowserPrint-2.1.18.min.js"></script>

Make a Function to print stickers

<script>
    // Initialize the Browser Print SDK
    BrowserPrint.init();
    function printStickers() {
        var numStickers = 5; // Number of stickers to print

        var zplCode = "^XA" +
                      "^FO100,100" +
                      "^A0N,50,50" +
                      "^FDHello, World!" +
                      "^FS" +
                      "^XZ";

        BrowserPrint.getDefaultDevice("printer", function (printer) {
            if (printer && printer.connection) {
                if (printer.connection === "usb" || printer.connection === "network") {
                    for (var i = 0; i < numStickers; i++) {
                        printer.send(zplCode, function () {
                            console.log("Sticker printed successfully.");
                        }, function (error) {
                            console.error("Failed to print sticker:", error);
                        });
                    }
                } else {
                    console.error("The selected printer is not a Zebra printer.");
                }
            } else {
                console.error("No printer available.");
            }
        }, function (error) {
            console.error("Error retrieving default printer:", error);
        });
    }

</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.