UNPKG

receiptline

Version:

Markdown for receipts. Printable digital receipts. Generate receipt printer commands and images.

70 lines (65 loc) 2.93 kB
<!-- Copyright 2019 Open Foodservice System Consortium Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>ReceiptLine JavaScript Example</title> <script type="text/javascript" src="receiptline.js"></script> <script type="text/javascript"> function initialize() { const load = document.getElementById('load'); const paper = document.getElementById('paper'); load.onclick = event => load.value = ''; load.onchange = event => { const file = event.target.files[0]; if (file) { const reader = new FileReader(); reader.onload = event => { // for SVG output const printer = { // cpl: characters per line (required) cpl: 48, // font: Courier, encoding: utf-8 (optional) encoding: 'multilingual', // upsideDown: ignored (optional) upsideDown: false, // spacing: line spacing (optional) spacing: false, // cutting: ignored (optional) cutting: true, // gamma: ignored (optional) gamma: 1.0, // command: SVG (optional) command: 'svg' }; const svg = receiptline.transform(reader.result, printer); const dom = new DOMParser().parseFromString(svg, 'image/svg+xml').documentElement; while (paper.hasChildNodes()) { paper.removeChild(paper.firstChild); } paper.appendChild(dom); } reader.readAsText(file); } }; } </script> </head> <body onload="initialize()" style="background-color: #eee;"> <label for="load">Load</label> <input id="load" type="file" accept=".receipt,text/plain"> <hr> <div id="paper" style="width: 576px; padding: 12px; background-color: #fff;"></div> </body> </html>