From 36956de62f68066734645eb3e4d9205a5d9e9970 Mon Sep 17 00:00:00 2001 From: "Rodrigo M. Albuquerque" Date: Mon, 8 Aug 2016 17:22:16 -0300 Subject: [PATCH] print multiple labels terminated by ^XZ --- ZplPrinter/js/main.js | 69 +++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/ZplPrinter/js/main.js b/ZplPrinter/js/main.js index 84a68fd..4e0d9cc 100644 --- a/ZplPrinter/js/main.js +++ b/ZplPrinter/js/main.js @@ -18,45 +18,50 @@ $(document).ready(function () { chrome.sockets.tcp.onReceive.addListener(function (info) { notify('{0} bytes received from Client: {1} Port: {2}'.format(info.data.byteLength, clientSocketInfo.peerAddress, clientSocketInfo.peerPort), 'print', 'info', 1000); - var zpl = String.fromCharCode.apply(null, new Uint8Array(info.data)); + var zpls = String.fromCharCode.apply(null, new Uint8Array(info.data)).split(/\^XZ/); chrome.sockets.tcp.close(info.socketId); var factor = (configs.unit == '1') ? 1 : (configs.unit == '2') ? 2.54 : 25.4; var width = parseFloat(configs.width) / factor; var height = parseFloat(configs.height) / factor; - var xhr = new XMLHttpRequest(); - xhr.open('POST', 'http://api.labelary.com/v1/printers/{0}dpmm/labels/{1}x{2}/0/'.format(configs.density, width, height), true); - xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); - xhr.responseType = 'blob'; - xhr.onload = function (e) { - if (this.status == 200) { - var blob = this.response; - if (configs['saveLabels']) { - if (configs['filetype'] == '1') { - saveLabel(blob, 'png'); - } else { - savePdf(zpl, configs.density, width, height); - } - } - var size = getSize(width, height) - var img = document.createElement('img'); - img.setAttribute('height', size.height); - img.setAttribute('width', size.width); - img.setAttribute('class', 'thumbnail'); - img.onload = function (e) { - window.URL.revokeObjectURL(img.src); - }; - - img.src = window.URL.createObjectURL(blob); - - $('#label').prepend(img); - var offset = size.height + 20; - $('#label').css({ "top": '-' + offset + 'px' }); - $('#label').animate({ "top": "0px" }, 1500); + for (var i in zpls) { + var zpl = zpls[i]; + if (zpl != "") { + zpl = zpl + "^XZ"; } - }; + var xhr = new XMLHttpRequest(); + xhr.open('POST', 'http://api.labelary.com/v1/printers/{0}dpmm/labels/{1}x{2}/0/'.format(configs.density, width, height), true); + xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + xhr.responseType = 'blob'; + xhr.onload = function (e) { + if (this.status == 200) { + var blob = this.response; + if (configs['saveLabels']) { + if (configs['filetype'] == '1') { + saveLabel(blob, 'png'); + } else { + savePdf(zpl, configs.density, width, height); + } + } + var size = getSize(width, height) + var img = document.createElement('img'); + img.setAttribute('height', size.height); + img.setAttribute('width', size.width); + img.setAttribute('class', 'thumbnail'); + img.onload = function (e) { + window.URL.revokeObjectURL(img.src); + }; - xhr.send(zpl); + img.src = window.URL.createObjectURL(blob); + + $('#label').prepend(img); + var offset = size.height + 20; + $('#label').css({ "top": '-' + offset + 'px' }); + $('#label').animate({ "top": "0px" }, 1500); + } + }; + xhr.send(zpl); + } }); });