Skip to content

nikuscs/printer-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🖨️ Thermal Printer API

Go API for BLE thermal printers. Print text, images, barcodes, receipts, and more.

✨ Features

  • Text: auto-wrap, alignment (left/center/right), bold, custom font size
  • Emoji: full Unicode emoji support (auto-downloaded from Google Noto)
  • Images: Floyd-Steinberg dithering, ASCII art mode, invert colors
  • Barcodes: Code128, Code39, EAN-13, QR codes
  • Templates: receipts, tables, calendar day views
  • GitHub PR: print PR details as a receipt
  • Multiple copies: ?times=N on all endpoints
  • API key auth: optional ?key= authentication
  • CLI + HTTP API: use from terminal or as a service

🖨️ Compatible Printers

Tested with cat-style BLE thermal printers:

  • X6h-8BA5 (default)
  • Other 384px-wide BLE printers using the same protocol

📦 Install

make build

Or download binaries from Releases.

🚀 Usage

CLI

./bin/print "Hello World"
./bin/print --align center "Centered text"
./bin/print --image photo.jpg

HTTP Server

./bin/server --port 8080
./bin/server --port 8080 --api-key mysecret  # with auth

📡 API Endpoints

Endpoint Method Description
/ GET Health check
/print POST Mixed content (text + images)
/print/text POST Plain text
/print/image POST Image from URL
/print/barcode POST Barcode/QR code
/print/receipt POST Receipt template
/print/table POST Table template
/print/calendar POST Calendar day view
/print/pr POST GitHub PR receipt
/feed POST Feed paper

Query Parameters

All print endpoints support:

  • ?times=N - print N copies (1-10)
  • ?key=XXX - API key (if auth enabled)

Quick Examples

# Text
curl -X POST "localhost:8080/print/text?text=Hello"

# Image with ASCII art mode
curl -X POST "localhost:8080/print/image?url=https://example.com/img.png&mode=ascii"

# Image inverted (white on black)
curl -X POST "localhost:8080/print/image?url=https://example.com/logo.png&invert=true"

# QR Code
curl -X POST "localhost:8080/print/barcode?data=https://example.com&type=qr"

# Receipt (2 copies)
curl -X POST "localhost:8080/print/receipt?times=2" \
  -H "Content-Type: application/json" \
  -d '{"header":"STORE","items":[{"name":"Item","quantity":1,"price":9.99}],"total":9.99}'

# GitHub PR
curl -X POST "localhost:8080/print/pr?url=https://github.com/owner/repo/pull/1"

See EXAMPLES.md for full documentation and more examples

⚙️ Configuration

Edit internal/config/config.go:

PrinterConfig{
    DeviceName:   "X6h-8BA5",  // BLE device name
    Speed:        15,          // 10-90, lower = better quality
    Energy:       14000,       // higher = darker
    PaperWidth:   384,
    CommandDelay: 20,          // ms between commands
    DPI:          50,
}

🤝 Contributing

  1. Fork the repo
  2. Create a feature branch
  3. Submit a PR

⚠️ Vibe Code Alert

This project was vibe coded with zero prior Go knowledge. Built entirely through AI-assisted development. If you see something cursed, that's why. PRs welcome.

📄 License

MIT

About

🖨️ Go API for BLE thermal printers. Print text, images, barcodes, receipts, and more. Model X6h-8BA5

Topics

Resources

Stars

Watchers

Forks

Contributors