Narrowly Preventing Mayhem

    TypeScript icon, indicating that this package has built-in type declarations

    0.2.7 • Public • Published

    Originally forked from here


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


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

    Tested manually on following environments or platforms

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


      yarn add @tillpos/xml-escpos-helper


    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"?>
        <align mode="center">
            <text-line size="1:0">{{title}}</text-line>
        <align mode="center">
          <text-line size="0:0">  {{{thankyouNote}}}</text-line>
        <line-feed />
        <paper-cut />
    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"?>
        <align mode="center">
            <text-line size="1:0">{{title}}</text-line>
          <image density="d24">
      const input = {
        title: 'PNG - base64',
        base64PngImage: `data:image/png;base64,iVBORw0KGgoAAA+P/AaNn2GPEMgEFAAAAAElFTkSuQmCC`
      const buffer = EscPos.getBufferFromTemplate(template, input);


    • [ ] 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

    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! ❤️


    npm i @tillpos/xml-escpos-helper

    DownloadsWeekly Downloads






    Unpacked Size

    66.8 kB

    Total Files


    Last publish


    • snehithvelma
    • lakshmaji-till
    • mdsiddiq-till