Giter Site home page Giter Site logo

escpos's Introduction

escpos

golang esc/pos Lib

A quick Example

package main

import (
	"bufio"
	"bytes"
	"image"
	"os"
	"strings"

	escpos "escposTest/lib"
	"github.com/olekukonko/tablewriter"
	qrcode "github.com/skip2/go-qrcode"
)
// https://github.com/seer-robotics/escpos/blob/master/escpos.go
func main() {
	var png []byte
	f, err := os.OpenFile("/dev/ttyUSB0",os.O_RDWR,0755)
	if err != nil {
		panic(err)
	}
	defer f.Close()

	w := bufio.NewWriter(f)
	p := escpos.New(w)

	p.Verbose = true

	p.Init()
	p.Beep(4)
	p.SetFontSize(2, 3)
	p.SetFont("B")
	p.SetReverse(0)
	p.WriteGBK("简体字转繁体字")
	p.SetFont("C")
	p.Write("test2")

	p.SetEmphasize(1)
	p.Write("hello")
	p.Formfeed()
	png, _ = qrcode.Encode("https://www.bing.com", qrcode.Low, 256)
	img, _, _ := image.Decode(bytes.NewReader(png))
	p.SetAlign("center")
	p.PrintImage(img)
	p.SetUnderline(1)
	p.SetFontSize(4, 4)
	p.Write("hello")
	p.SetReverse(1)
	p.SetFontSize(2, 4)
	p.Write("hello")
	p.FormfeedN(10)
	p.SetAlign("center")
	p.Write("test")
	p.Linefeed()



	p.SetEmphasize(0)
	p.SetReverse(0)
	p.SetFontSize(2, 2)
	p.SetUnderline(0)
	data := [][]string{
		[]string{"充值", "The Good", "500"},
		[]string{"找零", "The Ruby", "288"},
		[]string{"应收", "The Ugly", "120"},
		[]string{"实收", "The Gopher", "800"},
	}
	tableString := &strings.Builder{}
	table := tablewriter.NewWriter(tableString)
	table.SetHeader([]string{"Name", "Sign", "Rating"})

	for _, v := range data {
		table.Append(v)
	}
	table.SetAutoFormatHeaders(true)
	table.SetAutoMergeCells(true)
	table.SetAutoWrapText(true)
	table.SetBorder(true)
	table.Render() // Send output
	p.WriteGBK(tableString.String())
	p.Linefeed()
	p.Write("test")
	p.FormfeedD(200)

	p.Cut()

	w.Flush()
}

reference

escpos's People

Contributors

czyt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

sanrentai

escpos's Issues

如何打印在同一行

两段文本,一段居左一段居右,如何打印在同一行?使用MoveX可以实现吗?另外FormfeedN和FormfeedD写入的数据相同?
image

类似于最下面菜品数量这一行。

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.