Code Monkey home page Code Monkey logo

escpos's People

Contributors

david-yappeter avatar fossabot avatar hennedo avatar naikrovek avatar

Stargazers

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

Watchers

 avatar  avatar

escpos's Issues

WASM build failing

I'm trying to put it in WASM to be used with JS (in browser). But WASM build is failing.
Build cmd GOOS=js GOARCH=wasm go build -o main.wasm main.go

error

# github.com/qiniu/iconv
/home/user/go/pkg/mod/github.com/qiniu/[email protected]/reader.go:11:11: undefined: Iconv
/home/user/go/pkg/mod/github.com/qiniu/[email protected]/reader.go:19:19: undefined: Iconv
/home/user/go/pkg/mod/github.com/qiniu/[email protected]/reader.go:21:13: undefined: DefaultBufSize
/home/user/go/pkg/mod/github.com/qiniu/[email protected]/reader.go:49:14: undefined: EILSEQ
/home/user/go/pkg/mod/github.com/qiniu/[email protected]/writer.go:12:11: undefined: Iconv
/home/user/go/pkg/mod/github.com/qiniu/[email protected]/writer.go:19:19: undefined: Iconv
/home/user/go/pkg/mod/github.com/qiniu/[email protected]/writer.go:21:13: undefined: DefaultBufSize
/home/user/go/pkg/mod/github.com/qiniu/[email protected]/writer.go:70:15: undefined: EILSEQ
/home/user/go/pkg/mod/github.com/qiniu/[email protected]/writer.go:102:15: undefined: EILSEQ

Epson TMU220

Can i use this library with printer Epson TMU220 ?

Cyrillic

Thanks for the nice library.
There is one question.
How to send Russian characters for printing?
If you write a text in Russian, incomprehensible characters come out, apparently a conversion is needed.

Doesn't work on WASM

Even the WASM build failing, There's a PR which solves that.
By using that PR I'm able to build a WASM binay & successfully load into browser,

But the unfortunate thing is WASM doesn't supports direct TCP communication so net.Dial doesn't work.

tcp 192.168.0.121:9100: Connection refused

(works natively - when running the (documented) code from terminal)

Is there any plan/ way to do that?

The thing I'm trying is to ship a WASM that will handle swift printing from the client site (since the printer in is clients (local) network.

Is it even possible?

p.SetConfig unavailable

Hello,
Thank you for making this wonderful lib, I'm facing some issues setting config to the printer,

In the code snipet in the documentation p.SetConfig(escpos.ConfigEpsonTMT20II) is missing,
Following is the error

# command-line-arguments
./main.go:16:4: p.SetConfig undefined (type *escpos.Escpos has no field or method SetConfig)
./main.go:16:21: undefined: escpos.ConfigEpsonTMT20II

How to set config to the printer?

Libiconv dependency handling

I recently added this library in to a project that requires CGO (due to cross compilation needs), and because of that I compiled iconv as a static library (alternatively, I believe providing an install of the dynamic linked iconv library for the target machine would have also worked - however, I chose to compile and include iconv statically), as github.com/qiniu/iconv, required by this library, has the C "iconv" library as a dependency.

I think some mention of this requirement on the "target" system may be useful in the README; Would instructions for linking iconv statically and/or dynamically using CGO, and/or instructions on how to provide the proper iconv DLL on the target machine, also be something that would be useful to have in the README for this project? I am acutely aware that compile options and procedure for go code is hard to come by, so wanted to get your opinion on if adding something about how to do this in the README would be useful (in your opinion); If so, I can put together a PR with what I have found regarding installing iconv on the target system, and bundling it using CGO (I've been working on cross compiling and including iconv for an app I'm working on, so would be more than happy to share my notes for the README, if you think it'll be of use for others).

Also, thank you for providing this great escpos library; It helped me quite a bit recently with a few label formats I needed to print via escpos on a newer golang project.

XPrinter 48mm POS-5890K

For everyone who will be faced with printing gibberish on such model of printer.

During debugging the issue we experimentally figured out that it started printing gibberish when we send command GS v 0 with image height multiple of 48 only : i.e. 240, 192, 144, 96 .
We handled this case with spliting whole image into chunks of multiple of 256 and then if smaller chunk is multiple of 48 then increase image height on 8 and just fill that addition with 255 brightness pixels. Finally send chunks of GS v 0 one by one to the printer.

So it seems a bug with printer`s firmware rather than library issue

if someone needs a fix for such printer here one of the possible solutions

const (
	xPrinterBuggyImageDivisor = 48
)

type Image struct {
	Width  int
	Height int
	Pixels [][]pixel
}

func closestNDivisibleBy8(n int) int {
	q := n / 8
	n1 := q * 8
	if n1%xPrinterBuggyImageDivisor == 0 {
		n1 += 8
	}
	return n1
}

func getPixels(reader io.Reader) ([]Image, error) {

	img, _, err := image.Decode(reader)

	if err != nil {
		return []Image{}, err
	}

	bounds := img.Bounds()
	width, height := bounds.Max.X, bounds.Max.Y
	printWidth := closestNDivisibleBy8(width)
	printHeight := closestNDivisibleBy8(height)

	imageDivisor := 256
	imagesCount := printHeight / imageDivisor
	if printHeight%imageDivisor != 0 {
		imagesCount++
	}

	restTailHeight := printHeight - (imagesCount-1)*imageDivisor
	if restTailHeight%xPrinterBuggyImageDivisor == 0 {
		printHeight += 8
	}

	images := make([]Image, imagesCount)

	previous := 0
	for i := imagesCount; i > 0; i-- {
		localHeight := printHeight - (i-1)*imageDivisor - previous
		pixels := make([][]pixel, localHeight)

		for y := 0; y < localHeight; y++ {
			pixels[y] = make([]pixel, printWidth)
			for x := 0; x < printWidth; x++ {
				if x >= width || y+previous >= height {
					pixels[y][x] = pixel{0xff, 0xff, 0xff, 0x01}
				} else {
					pixels[y][x] = rgbaToPixel(img.At(x, y+previous).RGBA())
				}
			}
		}
		previous += localHeight
		images[imagesCount-i] = Image{printWidth, localHeight, pixels}
	}
	return images, nil
}

Printing images is extremely slow

Using an EPSON TM-T88II printer with this code snippet works (it prints the image) but is extremely slow. The printer prints one "line" of the image and waits for ~2 seconds, then prints the next line and so on. The printer is definitely capable of much faster printing, I'm also trying out the python-escpos library and that one spits out a complete image in under a second without any delay between lines.

Not sure what is happening here. The python library allows selecting between normal and "high density" mode when printing images, maybe that is the difference, but I don't see how to toggle it here.

	p := escpos.New(socket)
	p.SetConfig(escpos.ConfigEpsonTMT88II)

	f, err := os.Open("./logo.gif")
	if err != nil {
		panic(err)
	}
	defer f.Close()
	img, fmtName, err := image.Decode(f)

	if err != nil {
		panic(err)
	}

	p.PrintImage(img)

centering the QR code

printer.QRCode(QrUrl, true, 5, escpos.QRCodeErrorCorrectionLevelH)
I want to center the QR code that I created in this way, so I want it to add a space from the left and go a little more to the right, but I could not center it with any method. Is it possible to do this can you help please?

It didn't work even if I used lineSpacing before qr code generation :(

BrokenImport

Hello, I'm trying to use the README example and VSCode gives brokenimport error. I tried go mod tidy and go get the package, but still with error. Let me know what I can do to help.

Not cutting according to the printer model

PrintAndCut operation works with POSBANK A10 Thermal Receipt printer, but cutting cannot be performed on this Hugin GP-80250VN printer. Both are ESC/POS printers. I use the exact same code as the code. Can you help on this issue please ๐Ÿ™

Printing from a printer with an internal IP

I have a printer with internal IP of 192.168.0.10. And I am running the code below but it is not responding.

package main

import (
	"net"
	"github.com/hennedo/escpos"
)
func main() {
	socket, err := net.Dial("ip4:1", "192.168.0.10")
	if err != nil {
		println(err.Error())
	}
	defer socket.Close()

	p := escpos.New(socket)
	p.Size(2, 2).Write("TEST")
}

I guess it cannot connect. How do we find the part written "ip4:1", can you please help?

(edited by henne to wrap code into a code block)

can't read errors from the printer

I'm using this on a USB Epson TM-T88IV and if something isn't right during printing, the printer just ... stops. There's no way to know what is wrong because the only connection to the printer is through a Writer, and not a ReadWriter.

It is probably not trivial to implement, or maybe it is, but checking for an error after each WriteRaw and exposing that would be lovely.

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.