Package: escposprinter
Python library to manipulate ESC/POS Printers, now for python > 31. DependenciesIn order to start getting access to your printer, you must ensure
you have previously installed the following python modules:pyusb (python-usb)Pillow2. DescriptionPython ESC/POS is a library which lets the user have access to all
those printers handled by ESC/POS commands, as defined by Epson,
from a Python application.The standard usage is send raw text to the printer, but in also
helps the user to enhance the experience with those printers by
facilitating the bar code printing in many different standards,
as well as manipulating images so they can be printed as brand
logo or any other usage images migh have.Text can be aligned/justified and fonts can be changed by size,
type and weight.Also, this module handles some hardware functionalities like, cut
paper, carrier return, printer reset and others concerned to the
carriage alignment.3. Define your printerBefore start create your Python ESC/POS printer instance, you must
see at your system for the printer parameters. This is done with
the ‘lsusb’ command.First run the command to look for the “Vendor ID” and “Product ID”,
then write down the values, these values are displayed just before
the name of the device with the following format:xxxx:xxxxExample:Bus 002 Device 001: ID 1a2b:1a2b Device nameWrite down the the values in question, then issue the following
command so you can get the “Interface” number and “End Point”lsusb -vvv -d xxxx:xxxx | grep iInterface
lsusb -vvv -d xxxx:xxxx | grep bEndpointAddress | grep OUTThe first command will yields the “Interface” number that must
be handy to have and the second yields the “Output Endpoint”
address.By default the “Interface” number is “0” and the “Output Endpoint”
address is “0x82”,  if you have other values then you can define
with your instance.4. Define your instanceThe following example shows how to initialize the Epson TM-TI88IVNOTE: Always finish the sequence with Epson.cut() otherwise you will endup with weird chars being printed.
.. code:: pythonfrom escposprinter import *Epson = printer.Usb(0x04b8,0x0202)
Epson.text(‘Hello World’)
Epson.cut()or use with statement:importdatetimefromescposprinterimport*fromescposprinter.escposimportEscposIO,EscposprinterAddress='192.168.0.196'printerPort=9100defcheckPrinterAlive():if(printer.Network.isAlive(printerAddress,printerPort)):returnTrueelse:raiseException("Host is unreachable, socket communication was not opened")if(checkPrinterAlive()):string=str("String: "+str(datetime.datetime.now().microsecond))foriterationinrange(30):withEscposIO(printer.Network(printerAddress,printerPort))asp:p.set(font='a',codepage='cp1251',size='normal',align='center',bold=True)p.writelines('LOGO')p.printer.nvRamImage()#p.printer.image('IMAGE PATH')p.writelines('')p.writelines('')p.writelines('')p.writelines('')# After exit of with, printer will cut the paperThis method was implemented for both platforms: Linux and Windows5. APIEscpos() - main classEscpos.image(path_img) - Open image fileEscpos.nvRamImage() - Prints a previously downloaded (by third party specific tools) images from NVRAM (It allows to select the image to print and set the print image width options), by defaults it prints the first image in memory with the original dimensionsEscpos.qr(text, *args, **kwargs) - Print QR Code for the provided stringEscpos.barcode(code, bc, width, height, pos, font) - Print BarcodeEscpos.text(text) - Print any textEscpos.set(codepage=None, **kwargs) - kwargs should be:bold:        set bold fontunderline:   underline textsize:        Text sizefont:        Font typealign:       Text positioninverted:    White on black textcolor:       Text colorEscpos.cut() - Cut the paperEscpos.cashdraw(pin) - Send open cashdraw signal to printer pin.Escpos.control() and Escpos.hw() - Should be use it when you want to do another operations.EscposIO(printer, autocut=True, autoclose=True) - class for using with ‘with’ statement. When autocut=False printer not cut the paper after exit of “with”.EscposIO.set(**kwargs) - set the params in printing streambold:        set bold fontunderline:   underline textsize:        Text sizefont:        Font typealign:       Text positioninverted:    White on black textcolor:       Text colorEscposIO.writelines(text, **params) - Accept params like “set”, and apply them for this lines. You should use set() for setting common params.6. LinksOriginal Authors:
* Manuel F Martinez <manpaz@bashlinux.com>
* Dmitry Orlov <me@mosquito.su>This repo developer:
* Fardella Simone <fardella93@gmail.com>