GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - e11137/xml-escpos-helper

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

106 Commits
106 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.vscode
.vscode
 
 
examples
examples
 
 
resources
resources
 
 
src
src
 
 
.editorconfig
.editorconfig
 
 
.eslintignore
.eslintignore
 
 
.eslintrc
.eslintrc
 
 
.gitignore
.gitignore
 
 
.prettierignore
.prettierignore
 
 
.prettierrc
.prettierrc
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
package.json
package.json
 
 
tsconfig.build.json
tsconfig.build.json
 
 
tsconfig.json
tsconfig.json
 
 
tslint.json
tslint.json
 
 
yarn.lock
yarn.lock
 
 

Repository files navigation

Originally forked from here

ESC/POS XML

Cross platform JavaScript library that implements the thermal printer ESC / POS protocol and provides an XML interface for preparing templates for printing.

Features

  • Text
  • Text line
  • Feed line
  • Bold text
  • Underline text
  • Font size
  • Small mode
  • White mode
  • Align
  • Barcode
  • QRcode
  • Paper cut node
  • Image (base64) (png only)
  • XML with mustache

Tested manually on following environments or platforms

  • React Native (Android)
  • React Native (iOS)
  • React Native Web
  • Server side (NodeJs)
  • Desktop applications (nwjs & electron)
  • Other node environment (terminal)

Installation

  yarn add @tillpos/xml-escpos-helper

Examples

With an XML template + plain object input (regular text).

import { EscPos } from '@tillpos/xml-escpos-helper';

// store this template somewhere `s3` or as `static asset` based on your preference 
const template = `
  <?xml version="1.0" encoding="UTF-8"?>
  <document>
    <align mode="center">
      <bold>
        <text-line size="1:0">{{title}}</text-line>
      </bold>
    </align>

    {{#thankyouNote}}
    <align mode="center">
      <text-line size="0:0">  {{{thankyouNote}}}</text-line>
    </align>

    <line-feed />

    <paper-cut />
  </document>
`;

const input = {
  title: 'Sample',
  thankyouNote: 'Welcome...!'
};

const buffer = EscPos.getBufferFromTemplate(template, input);
// send this buffer to a stream (eg.: bluetooth or wifi)

With an XML template + png image (base64)

  const template =  `<?xml version="1.0" encoding="UTF-8"?>
  <document>
    <align mode="center">
      <bold>
        <text-line size="1:0">{{title}}</text-line>
      </bold>
        
      <image density="d24">
        {{base64PngImage}}
      </image>
    </align>    
  </document>`;

  const input = {
    title: 'PNG - base64',
    base64PngImage: `data:image/png;base64,iVBORw0KGgoAAA+P/AaNn2GPEMgEFAAAAAElFTkSuQmCC`
  };

  const buffer = EscPos.getBufferFromTemplate(template, input);

TODO

  • Font styles (font family)
  • Image bitmap conversion improvements
  • jpeg support
  • Add example apps to repo
  • Removed uglify for some reason, need to bring it back
  • Improve image rendering

Common issues

  • If there is any delay you observe while printing with this library it is mostly due to image manipulations (try without image 😷 )

Useful links / resources

  • ESC / POS Commands manual
  • A blog post explaiing about printing images with ESCPOS
  • Similar library for serverside - node-escpos.

Limitations on the react-native framework

  • FileReader.readAsArrayBuffer was not implemented.
  • Most of popular image manupulation libraries does not have support for react-native. eg : jimp, jpeg-js and sharp. We can use these libraries with some native node lib implemented in react native (some sort of polyfill).
  • For png this library seems to be faster, but when tested this library with it, it is not retaining pixels at some places)
  • Use this node-libs-react-native if we need to use this library in react native (adds some mock or js implementation for fs, stream etc)

Contributions of any kind welcome! ❤️

About

No description, website, or topics provided.

Resources

Readme
License
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.