print multiple labels terminated by ^XZ

This commit is contained in:
Rodrigo M. Albuquerque 2016-08-08 17:22:16 -03:00
parent a68caefd2b
commit 36956de62f

View File

@ -18,12 +18,17 @@ $(document).ready(function () {
chrome.sockets.tcp.onReceive.addListener(function (info) { chrome.sockets.tcp.onReceive.addListener(function (info) {
notify('{0} bytes received from Client: <b>{1}</b> Port: <b>{2}</b>'.format(info.data.byteLength, clientSocketInfo.peerAddress, clientSocketInfo.peerPort), 'print', 'info', 1000); notify('{0} bytes received from Client: <b>{1}</b> Port: <b>{2}</b>'.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); chrome.sockets.tcp.close(info.socketId);
var factor = (configs.unit == '1') ? 1 : (configs.unit == '2') ? 2.54 : 25.4; var factor = (configs.unit == '1') ? 1 : (configs.unit == '2') ? 2.54 : 25.4;
var width = parseFloat(configs.width) / factor; var width = parseFloat(configs.width) / factor;
var height = parseFloat(configs.height) / factor; var height = parseFloat(configs.height) / factor;
for (var i in zpls) {
var zpl = zpls[i];
if (zpl != "") {
zpl = zpl + "^XZ";
}
var xhr = new XMLHttpRequest(); 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.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.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
@ -55,8 +60,8 @@ $(document).ready(function () {
$('#label').animate({ "top": "0px" }, 1500); $('#label').animate({ "top": "0px" }, 1500);
} }
}; };
xhr.send(zpl); xhr.send(zpl);
}
}); });
}); });