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

3
.gitignore vendored
View File

@ -186,4 +186,5 @@ FakesAssemblies/
# LightSwitch generated files # LightSwitch generated files
GeneratedArtifacts/ GeneratedArtifacts/
_Pvt_Extensions/ _Pvt_Extensions/
ModelManifest.xml 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; padding: 0;
} }
webview {
height: 100%;
margin: 0;
width: 100%;
}
input:required:invalid, input:focus:invalid { border-color: #d9534f; } input:required:invalid, input:focus:invalid { border-color: #d9534f; }
::-webkit-scrollbar-thumb { display: none; } ::-webkit-scrollbar-thumb { display: none; }

View File

@ -16,17 +16,38 @@ $(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 = 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); 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;
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); var xhr = new XMLHttpRequest();
$('#label').prepend('<div class="thumbnail" style="width: {0}px; height: {1}px"><webview src="{2}" autosize="on" /></div>'.format(size.width, size.height, uri)); xhr.open('POST', 'http://api.labelary.com/v1/printers/{0}dpmm/labels/{1}x{2}/0/'.format(configs.density, width, height), true);
var offset = size.height + 20; xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
$('#label').css({ "top": '-' + offset + 'px' }); xhr.responseType = 'blob';
$('#label').animate({ "top": "0px" }, 1500); 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 // Stop tcp server
function stopTcpServer() { function stopTcpServer() {
if (socketId == undefined) return; 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)); notify('Printer stopped on <b>{0}</b> Port: <b>{1}</b>'.format(configs.host, configs.port));
socketId = undefined; socketId = undefined;
}); });
@ -109,7 +130,7 @@ function initEvents() {
} }
}); });
$('#btn-remove').click(function() { $('#btn-remove').click(function () {
var size = $('.thumbnail').size(); var size = $('.thumbnail').size();
if (size > 0) { if (size > 0) {
@ -123,8 +144,8 @@ function initEvents() {
} }
}); });
$('#btn-close').click(function() { $('#btn-close').click(function () {
chrome.storage.local.set({ isOn: $('#btn-on').hasClass('active') }, function() { chrome.storage.local.set({ isOn: $('#btn-on').hasClass('active') }, function () {
window.close(); window.close();
stopTcpServer(); 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')) { if ($('#btn-on').hasClass('active')) {
toggleSwitch('.btn-toggle'); toggleSwitch('.btn-toggle');
stopTcpServer(); stopTcpServer();
@ -193,7 +214,7 @@ function initConfigs() {
for (var key in configs) { for (var key in configs) {
if (key == 'density') { if (key == 'density') {
initDropDown('density', configs[key]); initDropDown('density', configs[key]);
}else if (key == 'unit') { } else if (key == 'unit') {
initDropDown('unit', configs[key]); initDropDown('unit', configs[key]);
} else if (key == 'isOn' && configs[key]) { } else if (key == 'isOn' && configs[key]) {
toggleSwitch('.btn-toggle'); toggleSwitch('.btn-toggle');

View File

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