Change labelary web service call from GET to POST to support large ZPL templates.

Resolves #1.
This commit is contained in:
sbinkert 2016-05-18 10:03:45 +02:00
parent a944b2379f
commit 955853ce12
7 changed files with 58 additions and 23 deletions

1
.gitignore vendored
View File

@ -187,3 +187,4 @@ FakesAssemblies/
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml
/.vs/config/applicationhost.config

19
README.md Normal file
View File

@ -0,0 +1,19 @@
# ZplPrinter
Printer emulator for zpl rendering engine.
Printer emulator for zpl rendering engine. The emulator is based on the [labelary](http://labelary.com/service.html) web service. You can configure print density, label size and the tcp server to listen for any incoming labels.
## References
* [ZPL Command Support](http://labelary.com/docs.html)
* [ZPL Web Service](http://labelary.com/service.html)
## Release notes
### Version 1.3
* **Change** Labelary web service call from GET to POST to support large ZPL templates. (Thanks to [pitufo](https://github.com/sbinkert/ZplPrinter/issues/1))
## Download
<a target="_blank" href="https://chrome.google.com/webstore/detail/zpl-printer/phoidlklenidapnijkabnfdgmadlcmjo"><img alt="Try it now" src="https://raw.github.com/GoogleChrome/chrome-app-samples/master/tryitnowbutton_small.png" title="Click here to install ZplPrinter from the Chrome Web Store"/></a>

Binary file not shown.

Binary file not shown.

View File

@ -8,12 +8,6 @@ body {
padding: 0;
}
webview {
height: 100%;
margin: 0;
width: 100%;
}
input:required:invalid, input:focus:invalid { border-color: #d9534f; }
::-webkit-scrollbar-thumb { display: none; }

View File

@ -16,17 +16,38 @@ $(document).ready(function () {
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);
var zpl = encodeURIComponent(String.fromCharCode.apply(null, new Uint8Array(info.data)));
var zpl = String.fromCharCode.apply(null, new Uint8Array(info.data));
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 uri = 'http://api.labelary.com/v1/printers/{0}dpmm/labels/{1}x{2}/0/{3}'.format(configs.density, width, height, zpl);
var size = getSize(width, height);
$('#label').prepend('<div class="thumbnail" style="width: {0}px; height: {1}px"><webview src="{2}" autosize="on" /></div>'.format(size.width, size.height, uri));
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;
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);
}
};
xhr.send(zpl);
});
});
@ -91,7 +112,7 @@ function startTcpServer() {
// Stop tcp server
function stopTcpServer() {
if (socketId == undefined) return;
chrome.sockets.tcpServer.close(socketId, function() {
chrome.sockets.tcpServer.close(socketId, function () {
notify('Printer stopped on <b>{0}</b> Port: <b>{1}</b>'.format(configs.host, configs.port));
socketId = undefined;
});
@ -109,7 +130,7 @@ function initEvents() {
}
});
$('#btn-remove').click(function() {
$('#btn-remove').click(function () {
var size = $('.thumbnail').size();
if (size > 0) {
@ -123,8 +144,8 @@ function initEvents() {
}
});
$('#btn-close').click(function() {
chrome.storage.local.set({ isOn: $('#btn-on').hasClass('active') }, function() {
$('#btn-close').click(function () {
chrome.storage.local.set({ isOn: $('#btn-on').hasClass('active') }, function () {
window.close();
stopTcpServer();
});
@ -148,7 +169,7 @@ function initEvents() {
});
$('#settings-window').on('shown.bs.modal', function() {
$('#settings-window').on('shown.bs.modal', function () {
if ($('#btn-on').hasClass('active')) {
toggleSwitch('.btn-toggle');
stopTcpServer();
@ -193,7 +214,7 @@ function initConfigs() {
for (var key in configs) {
if (key == 'density') {
initDropDown('density', configs[key]);
}else if (key == 'unit') {
} else if (key == 'unit') {
initDropDown('unit', configs[key]);
} else if (key == 'isOn' && configs[key]) {
toggleSwitch('.btn-toggle');

View File

@ -2,7 +2,7 @@
"manifest_version": 2,
"name": "Zpl Printer",
"short_name": "Zpl Printer",
"version": "1.2",
"version": "1.3",
"description": "Printer emulator for zpl rendering engine.",
"author": "Simon Binkert",
"app": {
@ -13,7 +13,7 @@
},
"permissions": [
"storage",
"webview"
"http://api.labelary.com/*"
],
"sockets": {
"tcpServer": {