Warm tip: This article is reproduced from stackoverflow.com, please click
barcode-printing emulation zpl zpl-ii zebra-printers

Barcode wasn't printed as many as the Request

发布于 2020-04-23 17:49:53

I was able to print raw ZPL commands from PHP directly to the printer, except that I can't print more than 1 label at once after update to on the TLP 2844-Z printer and my first time when installing WebClientPrint Processor (WCPP) in . When I was trying to emulate ZPL printer in the ZPL Printer app it also happened. The only exception was when I try this on the Safari browser, it's doing fine.


Working request script (still working in Safari, and previously in all other browser):

for(var i=0; i<rows.length; i++){
     javascript:jsWebClientPrint.print('useDefaultPrinter=' + $('#useDefaultPrinter').attr('checked') + '&printerName=' + $('#installedPrinterName').val() + '&param=' + rows[i].value);
}

What's preventing me was the permission asking:

wcp

on Chrome weren't generated as many time as the request were (which aren't the problem on Safari).


Example when request were 2: request

it only ask for permission once, resulting (only 1 label printed):

result

when it supposed to be (2 labels printed):

expected

I was able to reproduce the above by using the following script:

for (var i = 0; i < rows.length; i++) {
  var url = ('useDefaultPrinter=' + $('#useDefaultPrinter').attr('checked') + '&printerName=' + $('#installedPrinterName').val() + '&param=' + rows[i].value);
  window.open('webclientprint:' + domain + url);
}

Which aren't ideal since many tabs would be generated only to print, where previously you don't need any new tab to do the same.


Any idea how to solve this? So that it would print as many as the request ask?

Questioner
Mukyuu
Viewed
23
Mukyuu 2020-02-26 12:14

What I did to solve this was to make each request on a separate tab and closed the tab once it's executed. To make it simple I make it into a separate function.

Request script changed into:

for (var i = 0; i < rows.length; i++) {
  if (i > 0)
    delayPrint(rows[i], i); // separate function
  else
    javascript: jsWebClientPrint.print('useDefaultPrinter=' + $('#useDefaultPrinter').attr('checked') + '&printerName=' + $('#installedPrinterName').val() + '&param=' + rows[i].value);
}

separate function used for delaying request and to make each request on a separate tab and closed the tab once it's executed:

function delayPrint(data, interval) {
  setTimeout(function() {
    var wnd =   window.open('webclientprint:' + domain + ('useDefaultPrinter=' + $('#useDefaultPrinter').attr('checked') + '&printerName=' + $('#installedPrinterName').val() + '&param=' + rows[i].value));
    setTimeout(function() {
      wnd.close(); // close once it's done
    }, 1000);
  }, interval * 3000);
}