Giter Club home page Giter Club logo

thermalize's Introduction

thermalize

https://img.shields.io/github/v/tag/gromey/thermalize https://img.shields.io/github/license/gromey/thermalize

thermalize is a library that generates commands for thermal printers.

logo.png

Installation

thermalize can be installed like any other Go library through go get:

go get github.com/gromey/thermalize

Or, if you are already using Go Modules, you may specify a version number as well:

go get github.com/gromey/thermalize@latest

Getting Started

Example 1 (ESC/POS)

package main

import (
	"bytes"

	"github.com/gromey/thermalize"
	"github.com/phin1x/go-ipp"
)

func main() {
	w := new(bytes.Buffer)

	p := thermalize.NewEscape(48, 576, w, false)

	p.Init()
	p.CodePage(16)
	p.LineFeed()
	p.Align(thermalize.Center)
	p.Bold(true)
	p.Text("Hello world!", nil)
	p.LineFeed()
	p.FullCut()

	defer w.Reset()

	doc := ipp.Document{
		Document: w,
		Size:     w.Len(),
		Name:     "Test Page",
		MimeType: ipp.MimeTypeOctetStream,
	}

	client := ipp.NewIPPClient("localhost", 631, "", "", true)
	
	if _, err := client.PrintJob(doc, "your_printer_name", nil); err != nil {
		panic(err)
    }
}

Example 2 (Star)

package main

import (
	"bufio"
	"os"

	"github.com/gromey/thermalize"
)

func main() {
	f, err := os.OpenFile("/dev/ttyUSB0", os.O_RDWR, 0755)
	if err != nil {
		panic(err)
	}
	defer func() { _ = f.Close() }()

	w := bufio.NewWriter(f)

	p := thermalize.NewStar(48, 576, w, false)

	p.Init()
	p.CodePage(32)
	p.LineFeed()
	p.Align(thermalize.Center)
	p.Bold(true)
	p.Text("Hello world!", nil)
	p.LineFeed()
	p.FullCut()

	if err = w.Flush(); err != nil {
		panic(err)
	}
}

Example 3 (Image)

package main

import (
	"bufio"
	"os"

	"github.com/gromey/thermalize"
)

func main() {
	f, err := os.OpenFile("/dev/ttyUSB0", os.O_RDWR, 0755)
	if err != nil {
		panic(err)
	}
	defer func() { _ = f.Close() }()
	
	w := bufio.NewWriter(f)

	p := thermalize.NewEscape(48, 576, w, false)

	// To change the level of gray that should be visible when printing, change GrayLevel setting.
	// Default is 127.
	thermalize.GrayLevel = 150

	p.Init()
	p.LineFeed()
	p.Align(thermalize.Center)

	// Before you send an image to print, you must ensure
	// that its width is less than or equal to the width of the print area.
	p.Image(thermalize.Logo(), false)
	p.LineFeed()
	p.FullCut()

	if err = w.Flush(); err != nil {
		panic(err)
	}
}

thermalize's People

Contributors

gromey avatar

Watchers

 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.