Skip to content

POS Printer is a Go library that provides a unified, developer-friendly interface for communicating with a wide range of POS (Point of Sale) printer models. Designed with a clean and modular architecture, it simplifies the process of sending commands to thermal printers, whether you need to print text, generate QR codes, or render images.

Notifications You must be signed in to change notification settings

adcondev/pos-printer

Repository files navigation

POS Printer: A Modular Go Library for Thermal Printers

CI Status Go Report Card License: MIT Go.Dev reference Mentioned in Awesome Go Go Version Release Coverage Docker


POS Printer Logo

A modular, extensible library for thermal printer communication across multiple protocols

📝 Table of Contents

📝 Overview

POS Printer is a Go library that provides a unified, developer-friendly interface for communicating with a wide range of POS (Point of Sale) printer models. Designed with a clean and modular architecture, it simplifies the process of sending commands to thermal printers, whether you need to print text, generate QR codes, or render images. With comprehensive test coverage and support for multiple connection types, this library is built for reliability in production environments.

✨ Key Features

  • Multi-Protocol Support: Native support for ESC/POS and ZPL, with an extensible architecture to add more.
  • Flexible Connection Options: Connect to printers via Serial, USB, Network (TCP/IP), or Bluetooth.
  • Protocol-Agnostic Image Printing: A powerful imaging package that handles direct bitmap generation from image files.
  • Centralized Printer Registry: Manage multiple printer configurations in a centralized system, making it easy to switch between devices.
  • Comprehensive Testing: Includes a full suite of unit tests, mocks, and fakes to ensure stable and predictable behavior.
  • Well-Documented and Idiomatic Go: Clean, commented code that follows modern Go best practices.

🏗️ Architecture Diagram

The library is designed with a decoupled architecture, where each core functionality is separated into its own package. This allows for easy extension and maintenance.

graph TD
    A[Application] --> B{pos Printer API}

    subgraph "Core Library"
        B --> C[Printer Registry]
        B --> D[Connection Manager]
        B --> E{Protocols}
    end

    subgraph "Connection Layer"
        D --> F[USB]
        D --> G[Network]
        D --> H[Serial]
        D --> I[Bluetooth]
    end

    subgraph "Protocols Layer"
        E --> J[ESC/POS]
        E --> K[ZPL]
        E --> L[Imaging]
    end

    J --> M[Physical Printer]
    K --> M
    L --> M
Loading

🚀 Installation

To get started, add the library to your Go project using go get:

go get github.com/adcondev/pos-printer

💡 Usage Example

Here’s a simple example of how to connect to a printer and print a "Hello, World!" message.

package main

import (
	"log"

	"github.com/adcondev/pos-printer/escpos"
	"github.com/adcondev/pos-printer/pos"
)

func main() {
	// 1. Create a new printer profile in the registry
	registry := pos.NewPrinterRegistry()
	printerProfile := &pos.Printer{
		Name: "MyReceiptPrinter",
		Device: &pos.Device{
			Connector: &pos.NetworkConnector{Address: "192.168.1.100:9100"},
		},
	}
	registry.Add("my_printer", printerProfile)

	// 2. Get the printer from the registry
	p, err := registry.Get("my_printer")
	if err != nil {
		log.Fatalf("Failed to get printer: %v", err)
	}

	// 3. Connect to the printer
	if err := p.Connect(); err != nil {
		log.Fatalf("Failed to connect: %v", err)
	}
	defer p.Close()

	// 4. Send a command
	cmd := escpos.NewPrinter(p.Device.Connector)
	if err := cmd.Print("Hello, World!\n"); err != nil {
		log.Fatalf("Failed to print: %v", err)
	}

	log.Println("Successfully printed!")
}

🖨️ Supported Protocols

Protocol Status Description
ESC/POS ✅ Stable Epson Standard Code for Point of Sale Printers
ZPL 🔄 In Progress Zebra Programming Language for label printers
Image ✅ Stable Direct bitmap generation for any printer

🗺️ Roadmap

  • Full support for the ZPL protocol.
  • Add support for Bluetooth connections.
  • Implement a more advanced logging system.
  • Create a web-based interface for managing printers.

🤝 Contributing

Contributions are welcome! If you'd like to help improve the library, please feel free to fork the repository, make your changes, and submit a pull request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'Add some AmazingFeature').
  4. Push to the branch (git push origin feature/AmazingFeature).
  5. Open a Pull Request.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


Built with ❤️ by adcondev

About

POS Printer is a Go library that provides a unified, developer-friendly interface for communicating with a wide range of POS (Point of Sale) printer models. Designed with a clean and modular architecture, it simplifies the process of sending commands to thermal printers, whether you need to print text, generate QR codes, or render images.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 7