diff --git a/README.md b/README.md index ff5fd5d..cd1ae97 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,44 @@ -# ZplPrinter +# Zpl - Esc/Pos Printer -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. +Printer emulator for Zpl, Esc/Pos 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. -[Releases](https://github.com/erikn69/ZplPrinter/releases/latest) +[Releases](https://github.com/erikn69/ZplEscPrinter/releases/latest) -## New in Version 2.0 +## New in Version 3.0 -The app now runs standalone via Electron and can be installed via the binaries/zips on the GitHub Releases page. It currently supports: +The app now emulates Epson ESC/POS. The emulator is based on the [receipt-print-hq/escpos-tools](https://github.com/receipt-print-hq/escpos-tools/blob/master/esc2html.php) repo by @mike42, and can be installed via the binaries/zips on the GitHub Releases page. It currently supports * Windows: - * Squarrel installer (zpl-printer-**version**-win32-**arch**-setup.exe) - * Portable runner (zpl-printer-portable-**version**.exe) - * NuGet package (zpl-printer-**version**-full.nupkg) + * Squarrel installer (zpl-escpos-printer-**version**-win32-**arch**-setup.exe) + * Portable runner (zpl-escpos-printer-portable-**version**.exe) + * NuGet package (zpl-escpos-printer-**version**-full.nupkg) * msi installer (TODO) * Linux: - * Rpm (zpl-printer-**version**.**arch**.rpm) - * Deb (zpl-printer\_**version**\_**arch**.deb) - * Zip (Zpl.Printer-linux-**arch**-**version**.zip) + * Rpm (zpl-escpos-printer-**version**.**arch**.rpm) + * Deb (zpl-escpos-printer\_**version**\_**arch**.deb) + * Zip (Zpl-EscPos.Printer-linux-**arch**-**version**.zip) * Mac: - * Zip (Zpl.Printer-darwin-**arch**-**version**.zip) + * Zip (Zpl-EscPos.Printer-darwin-**arch**-**version**.zip) + +## New in Version 2.0 + +The app now runs standalone via Electron. ## References * [ZPL Command Support](http://labelary.com/docs.html) * [ZPL Web Service](http://labelary.com/service.html) * [Electron](https://www.electronjs.org) * [Electron Forge](https://www.electronforge.io) +* [Esc/Pos receipt print tools](https://github.com/receipt-print-hq/escpos-tools) ## Release notes +### Version 3.0 +* **Refactor** Reworked code +* **New** Esc/Pos Support +* **Fix** Bug fixes + ### Version 2.2 * **Refactor** Reworked code * **Upgrade** Bump dependencies diff --git a/ZplPrinter/css/style.css b/ZplEscPrinter/css/style.css similarity index 81% rename from ZplPrinter/css/style.css rename to ZplEscPrinter/css/style.css index dbea1f0..cdb437b 100644 --- a/ZplPrinter/css/style.css +++ b/ZplEscPrinter/css/style.css @@ -5,7 +5,16 @@ display: none; } -img.thumbnail { +.panel-heading-blur { + background-color: #445da5 !important; + border-color: #215480 !important; +} + +.label-container { + height: 82vh; +} + +.label-zpl { margin: 5px 0px 20px 5px; } diff --git a/ZplPrinter/icons/Icon-128.png b/ZplEscPrinter/icons/Icon-128.png similarity index 100% rename from ZplPrinter/icons/Icon-128.png rename to ZplEscPrinter/icons/Icon-128.png diff --git a/ZplPrinter/icons/Icon-16-white.png b/ZplEscPrinter/icons/Icon-16-white.png similarity index 100% rename from ZplPrinter/icons/Icon-16-white.png rename to ZplEscPrinter/icons/Icon-16-white.png diff --git a/ZplPrinter/icons/Icon-16.png b/ZplEscPrinter/icons/Icon-16.png similarity index 100% rename from ZplPrinter/icons/Icon-16.png rename to ZplEscPrinter/icons/Icon-16.png diff --git a/ZplPrinter/icons/Icon-24.png b/ZplEscPrinter/icons/Icon-24.png similarity index 100% rename from ZplPrinter/icons/Icon-24.png rename to ZplEscPrinter/icons/Icon-24.png diff --git a/ZplPrinter/icons/Icon-32.png b/ZplEscPrinter/icons/Icon-32.png similarity index 100% rename from ZplPrinter/icons/Icon-32.png rename to ZplEscPrinter/icons/Icon-32.png diff --git a/ZplPrinter/icons/Icon-64.png b/ZplEscPrinter/icons/Icon-64.png similarity index 100% rename from ZplPrinter/icons/Icon-64.png rename to ZplEscPrinter/icons/Icon-64.png diff --git a/ZplPrinter/icons/icon-1024.png b/ZplEscPrinter/icons/icon-1024.png similarity index 100% rename from ZplPrinter/icons/icon-1024.png rename to ZplEscPrinter/icons/icon-1024.png diff --git a/ZplPrinter/icons/icon.svg b/ZplEscPrinter/icons/icon.svg similarity index 100% rename from ZplPrinter/icons/icon.svg rename to ZplEscPrinter/icons/icon.svg diff --git a/ZplEscPrinter/js/main.js b/ZplEscPrinter/js/main.js new file mode 100644 index 0000000..6ba32de --- /dev/null +++ b/ZplEscPrinter/js/main.js @@ -0,0 +1,484 @@ +const $ = global.$ = global.jQuery = require('jquery'); +const createPopper = global.createPopper = require('@popperjs/core'); +const Bootstrap = global.Bootstrap = require('bootstrap'); +const { ipcRenderer } = require('electron'); +const fs = require('fs');; +const net = require('net'); +const bootbox = require('bootbox'); + +let clientSocketInfo; +let server; +let configs = {}; + +const defaults = { + isZpl: true, + isOn: true, + density: '8', + width: '4', + height: '6', + unit: '1', + host: '127.0.0.1', + port: '9100', + bufferSize: '4096', + keepTcpSocket: true, + saveLabels: false, + filetype: '3', + path: null, + counter: 0 +}; + +$(function () { + $(window).bind('focus blur', function () { + $('#panel-head').toggleClass('panel-heading-blur'); + }); + + // todo only on first run + if (!global.localStorage.getItem('isOn')) { + Object.entries(defaults).forEach(function ([k, v]) { + if (global.localStorage.getItem(k)) { + global.localStorage.setItem(k, v); + } + }); + } +}); +$(document).ready(function () { + Object.keys(defaults).forEach(function (k) { + configs[k] = global.localStorage.getItem(k); + }); + + initEvents(); + initConfigs(); +}); +function getSize(width, height) { + const defaultWidth = 386; + + const factor = width / height; + return { + width: defaultWidth, + height: defaultWidth / factor + }; +} +async function saveLabel(blob, ext, counter) { + const fileName = `LBL${counter.padLeft(6)}.${ext}`; + const path = !configs.path || configs.path==='null' ? '' : configs.path.trimCharEnd('\\').trimCharEnd('/'); + + try { + fs.writeFileSync(path + '/' + fileName, typeof blob === 'string' ? blob : new Uint8Array(await blob.arrayBuffer())) + // file written successfully + notify('Label {0} saved in folder {1}'.format(fileName, path), 'floppy-saved', 'info', 1000); + } catch (err) { + console.error(err); + notify(`error in saving label to ${fileName} ${err.message}`, 'floppy-saved', 'danger', 0); + } + +} +async function fetchAndSavePDF(api_url, zpl, counter) { + let r1 = await fetch(api_url, { + method: "POST", + body: zpl, + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Accept': 'application/pdf' + } + }) + + if (!r1.ok || r1.status !== 200) { + console.log('error in fetching pdf', `status = ${r1.status}`, await r1.text(), `zpl=${zpl}`) + return + } + + let blob = await r1.blob() + await saveLabel(blob, 'pdf', counter); +} +// Display notification +// @param {String} text Notification text +// @param {Number} glyphicon Notification icon +// @param {String} type Notification type +// @param {Number} delay Notification fade out delay in ms +function notify(text, glyphicon, type, delay) { + const log = $('
' + text + '
').text(); + if (type === 'danger') { + console.error(log); + } else { + console.info(log); + } + + let el = $(`