npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

thermal-ticket-printer

v0.1.5

Published

A npm package for printing thermal tickets.

Downloads

6

Readme

Thermal Ticket Printer

Thermal Ticket Printer is a npm package that provides a TypeScript class to process and print thermal tickets using a thermal printer. It supports rendering tickets from an XML template and printing them with customizable formatting options.

Installation

To use this module in your TypeScript project, you'll need to install the required dependencies:

npm install thermal-ticket-printer

Usage

  1. Import the Module

    Import the ThermalTicketPrinter class from thermal-ticket-printer in your TypeScript file:

    import { ThermalTicketPrinter } from 'thermal-ticket-printer';
  2. Prepare Ticket Data

    Define the data for your thermal ticket. For example:

    const ticketData = {
        current_date: '2024-04-03',
         items: [
             { name: 'Item 1', quantity: 2, price: 10.99 },
             { name: 'Item 2', quantity: 1, price: 5.99 },
         ],
         total_amount: 27.97,
    };
  3. Define Printer Configuration

    Set up the printer configuration, including the interface (e.g., /dev/usb/lp2):

    const printerInterface: string = '/dev/usb/lp2'; // Your printer interface
  4. Create Printer Instance

    Create an instance of ThermalTicketPrinter with the template path and printer interface:

    const printer = new ThermalTicketPrinter(printerInterface);
  5. Print the Ticket

    Call the printTicket method of the printer instance with the ticket data:

    printer.printTicket('path/to/your/template.xml', ticketData)
        .then(() => {
            console.log('Ticket printed successfully.');
        })
        .catch((error) => {
            console.error('Error printing ticket:', error);
        });

XML Template

The XML template defines the structure of the thermal ticket. It follows a specific format and structure to properly render the ticket elements. Here's an example of an XML template:

<!DOCTYPE ticket SYSTEM "ticket-receipt.dtd">
<ticket width="32">
   <alignment alignment="CENTER">
      <img src="templates/resources/logo.png"/>
      <text underline="true" bold="true">Store Name</text>
      <linebreak/>
      <text>Date: {{ current_date }}</text>
   </alignment>
   <linebreak/>

   <table>
      <tr>
         <td width=".4">Item</td>
         <td width=".2">Qty</td>
         <td>Price</td>
      </tr>
      {{#items}}
      <tr>
         <td width=".4" alignment="LEFT">{{ name }}</td>
         <td width=".2" alignment="RIGHT">{{ quantity }}</td>
         <td alignment="RIGHT">{{ price }}</td>
      </tr>
      {{/items}}
   </table>
   <linebreak/>

   <text bold="true">Total: {{ total_amount }}€</text>
   <linebreak/>

   <text>Thank you for shopping with us!</text>
</ticket>

Modify this template to fit your specific ticket layout. The template uses placeholders ({{ ... }}) which will be replaced with the actual data when rendering the ticket.

Sample Files

The package includes sample files to help you get started:

  • templates/ticket-receipt.dtd: This file is the DTD for a thermal ticket.
  • templates/ticket-template.xml: This file is an example XML template for a thermal ticket.

You can use these sample files as templates for creating your own thermal tickets. To access them, install the package and navigate to the templates directory in the installed package directory.

There is also the full TS + XML sample files in the folder example to test rapidly the config

License

This module is licensed under the MIT License. Feel free to modify and use it in your projects.

Author

Created by Cabrasky - Javier Mateos Mata

Issues and Contributions

If you encounter any issues or have suggestions for improvement, please open an issue on the GitHub repository: thermal-ticket-printer

Contributions are welcome! Fork the repository, make your changes, and submit a pull request.