1 Reply Latest reply on May 8, 2018 3:55 PM by Robin West

    Print queue

    Marcel Jong

      I'm facing a problem with my Zebra browser printing code.

       

      I'm using the following code:

       

      var url = 'http://www.example.com/image.jpg';

      selected_device.sendUrl(url, undefined, errorCallback);

       

      Result: ok

       

      Then I'm using a loop to print more labels:

       

      var url = 'http://www.example.com/';

      var i = 0;

       

      for (; i < 10; ) {

           url += i + '.jpg';
           // http://www.example.com/1.jpg, http://www.example.com/2.jpg ...

           selected_device.sendUrl(url, undefined, errorCallback);

       

           i++;

      }

       

      So the following images should print:

      http://www.example.com/1.jpg

      http://www.example.com/2.jpg

      http://www.example.com/3.jpg

      http://www.example.com/4.jpg

      http://www.example.com/5.jpg

       

      But when I check my labels, the order isn't correct, the labels are printed in the following order:

       

      http://www.example.com/1.jpg

      http://www.example.com/2.jpg

      http://www.example.com/4.jpg

      http://www.example.com/3.jpg

      http://www.example.com/5.jpg

       

      Does anyone have an idea how I can solve this?

        • Re: Print queue
          Robin West

          Hi Marcel,

          If order matters, I would recommend implementing the finishedCallback. I think, because you are not waiting till the system has sent each one before sending the next, they may be getting mixed up by the time they get to the printer.  Something like this should work:

           

          var url;
          var i;  //global or you can use cookies.
          function initialPrintFunction()
          {
            url = 'http://www.example.com/';
           i = 0;
          
            printNext();
          }
          
          function printNext()
          {
            if (i < 10)
            {
              url += i + '.jpg';
              i++;
              selected_device.sendUrl(url, finishedSendCallback, errorCallback);
            }
          }
          
          function finishedSendCallback()
          {
            printNext();
          }