Giter Site home page Giter Site logo

thermal-driver's Introduction

@node-escpos



๐Ÿ–จ๏ธ ESC/POS Printer driver for Node.js.


Hacktober Badge


demo.mp4

[๐Ÿ“ข RFC] Recently I'm working on a new workflow that prints the receipt. HTML+CSS will customize the content. Theoretically, we can print anything that we want. The workflow is like this:

  1. ๐ŸŽจ rendering
<div id="label-dom"> Label/Receipt </div>
  1. ๐Ÿ“ธ capturing
const screenshort = await capture(document.getElementByID("label-dom"))
  1. ๐Ÿงพ printing
const printer = await printer.image(screenshort, "s8")
printer.cut().close()

But my full-time job is very busy. So the progress is slow, And any sponsorship will encourage me to work more actively in the open-source community.


Improvements

  • ๐Ÿ›  TypeScript.
  • ๐Ÿ“ฆ pnpm.
  • ๐ŸŸข vitest.
  • ๐Ÿš€ More stable maintenance.
  • ๐Ÿ”ด Printing by HTML+CSS(WIP).
  • ๐Ÿ’ก More ideas.
  • ...

Packages

Example

import { Printer, Image } from "@node-escpos/core";
// install escpos-usb adapter module manually
import USB from "@node-escpos/usb-adapter";
// Select the adapter based on your printer type
import { join } from "path";

const device = new USB();

device.open(async function(err){
  if(err){
    // handle error
    return
  }

  // encoding is optional
  const options = { encoding: "GB18030" /* default */ }
  let printer = new Printer(device, options);

  // Path to png image
  const filePath = join("/PATH/TO/IMAGE");
  const image = await Image.load(filePath);

  printer
    .font("a")
    .align("ct")
    .style("bu")
    .size(1, 1)
    .text("May the gold fill your pocket")
    .text("ๆญๅ–œๅ‘่ดข")
    .barcode(112233445566, "EAN13", { width: 50, height: 50 })
    .table(["One", "Two", "Three"])
    .tableCustom(
      [
        { text: "Left", align: "LEFT", width: 0.33, style: "B" },
        { text: "Center", align: "CENTER", width: 0.33 },
        { text: "Right", align: "RIGHT", width: 0.33 },
      ],
      { encoding: "cp857", size: [1, 1] }, // Optional
    )
    
  // inject qrimage to printer
  printer = await printer.qrimage("https://github.com/node-escpos/driver")
  // inject image to printer
  printer = await printer.image(
    image, 
    "s8" // changing with image
  )

  printer
    .cut()
    .close()
});

Sponsors

License

MIT License ยฉ 2022 Dohooo

thermal-driver's People

Contributors

dohooo avatar dschweinbenz avatar github-actions[bot] avatar lucasfernog avatar alantoa avatar gronxb avatar

Stargazers

Roman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.