apdevelopment
apdevelopment

Reputation: 21

POS receipt print cannot make paper cut using python

Problem

We are working on a bigger project where we need to make a POS receipt print. We are able to make a print through the browser but the problem is that we cannot make a cut or a partial cut.

Win32 API

We have tried with Win32 API which work as well but we cannot find a command telling the receipt printer to "cut".

We have tried the following with win32:

from win32 import win32api
import win32print
txt = " Hello test ".encode()
p = win32print.OpenPrinter("EPSON TM-T20II Receipt")
job = win32print.StartDocPrinter (p, 1, ("test of raw data", None, "RAW"))
win32print.StartPagePrinter (p)
win32print.WritePrinter (p, txt)
win32print.EndPagePrinter (p)
win32print.ClosePrinter(p)

We have tried ending the print with these commands, without any luck.

win32print.EndDoc(p)
win32print.EndPagePrinter(p) 
win32print.EndDocPrinter(p11)

Other commands

Then we found other web pages saying that we should send a specific command to the printer, to make the cut. In that approach we had to initialise the printer differently. We made a few tries to do that.

p = printer.Usb( 0x04b8 , 0x0202 )

That gave the error NoBackendError, which was solved by installing libusb-win32-devel-filter-1.2.6.0.exe, and then we got USBNotFoundError.

Then we tried

p = Usb( 0x04b8 , 0x0202 , 0 , profile="TM-T20II")

Which said: Unexpected keyword argument 'profile'.

We did a little to solve that, but didn’t succeed.

Then we wrote:

from escpos.connections import getUSBPrinter
p = getUSBPrinter()(idVendor= 0x1504,
                    idProduct= 0x0006,
                    inputEndPoint= 0x82,
                    outputEndPoint= 0x01)

With the error: Cable isn’t plugged in. Tried to install a libusb-win32filter, again without luck.

Went back to the win32 Api, and found these links: C# CUSTOM VKP80iii Paper Ejector/Paper Cut What is the paper cut command? https://mike42.me/blog/what-is-escpos-and-how-do-i-use-it

Okay, the mindset now is to make a command to the pos print. We knew that commands to the pos print, wasn’t our best thing, but the idea was that the text was sent to the printer with the commands:

Settings

Last but not least, we found the pos printer on the computer, went into the settings, to see if there was some settings we could change to make it cut. And you guessed it, we had no success. But we tried to print some test prints, and when doing that, it made the partial cut without any problem.

Upvotes: 0

Views: 1848

Answers (2)

Tinashe Mphisa
Tinashe Mphisa

Reputation: 35

For cutting in EPSON TM-T2... POS printers, this worked for me.

win32print.WritePrinter (p, txt)
win32print.WritePrinter (p, b"\x1B@\x1DV1")
win32print.EndPagePrinter (p)

Upvotes: 0

Alex P.
Alex P.

Reputation: 31716

For full cut

win32print.WritePrinter(p, b'\x1dV\x00')

For partial cut

win32print.WritePrinter(p, b'\x1dV\x01')

Upvotes: 0

Related Questions