skip to navigation
skip to content

python-printer-escpos 0.0.3

Python interface for ESCPOS Printers

Package Documentation

Python Printer ESCPOS

Documentation

If you are just starting up with POS RECEIPT Printers, you must first refer to http://pythonhosted.org/python-printer-escpos/ to get started.

python-printer-escpos provides four different types of printer connections to talk to a ESCPOS printer.

Installation

Get some prerequisites first for image printing etc.

pip install Pillow

Install python-printer-escpos

pip install python-printer-escpos

Creating printer objects

USB Printer

If your printer is connected by a USB interface use this connection mode

from escpos.connections import getUSBPrinter


printer = getUSBPrinter()(idVendor=0x1504,
                          idProduct=0x0006
                          inputEndPoint=0x82,
                          outputEndPoint=0x01) # Create the printer object with the connection params

printer.text("Hello World")
printer.lf()

Network Printer

If your printer is on a network use this connection mode. 9100 is the most common port number for receipt printers. However you must check your printer manual to get the correct port number for your printer.

Synposis

from escpos.connections import getNetworkPrinter


printer = getNetworkPrinter()(host='192.168.0.20', port=9100)

printer.text("Hello World")
printer.lf()

Serial Printer

You printer may also be connected over a RS232 serial interface. You must get the correct baudrate for your printer for a serial connection.

Synposis

from escpos.connections import getSerialPrinter


printer = getSerialPrinter()(dev='/dev/ttyS0',
                          baudrate=9600)

printer.text("Hello World")
printer.lf()

Device File Printer

If you are unable to figure out how to use the other connection modes, you can try printing directly to the printer device file. This works in most use cases, however you will not be able to use the read device status functionality in this mode.

Synposis

from escpos.connections import getFilePrinter


printer = getFilePrinter()(dev='/dev/ttys2')

printer.text("Hello World")
printer.lf()

Examples

Printing Hello World

printer.text("Hello World")
printer.lf()

Printing a image

Prints a image to the printer( max width: 512px, max height: 255px)

printer.image('/home/shantanu/companylogo.gif')

Aligning Printouts

Set text alignment for your text.

printer.align('center')
printer.text('This text is center aligned')
printer.align('right')
printer.text('This text is right aligned')

Changing char spacing

Set spacing between each letter in printout.

printer.charSpacing(1)
printer.text('This text has normal right char spacing')
printer.lf()
printer.charSpacing(5)
printer.text('This text has 5 right char spacing')
printer.lf()

Changing print color(only on some models)

This function is supported in some printers, particularly dot matrix receipt printers with two color ribbons.

printer.color()
printer.text('This text is in primary color')
printer.lf()
printer.color(1)
printer.text('This text is in color 1')
printer.lf()

Change font height

Set font height.

printer.doubleHeight()
printer.text('This text is double height text')
printer.lf()
printer.doubleHeight(False)
printer.text('This text is not double height')
printer.lf()

Change font to double width

Set font width.

printer.doubleWidth()
printer.text('This text is double width text')
printer.lf()
printer.doubleWidth(False)
printer.text('This text is not double width')
printer.lf()

Switching font

Switch between printer fonts. Limited fonts are supported, mostly just ‘a’ or ‘b’

printer.font('b')
printer.text('This text is in font b')
printer.lf()
printer.font('a')
printer.text('This text is in font a')
printer.lf()

Invert text(black on white to white on black)

Invert printing so it prints in white over a black background.

printer.invert()
printer.text('This text is in inverted colors')
printer.lf()
printer.invert(False)
printer.text('This text is not in inverted colors')
printer.lf()

Set left margin

Set left margin.

printer.leftMargin(30)
printer.text('This text has left Margin of 30')
printer.lf()

Set line spacing

Set spacing between lines.

printer.lineSpacing()
printer.text('This text has 1/6 inch line spacing')
printer.lf()
printer.lineSpacing(5)
printer.text('This text has 5/60 inch line spacing')
printer.lf()

Set print area width

Set width of printable area.

printer.printAreaWidth(200)
printer.text('Set print area width to 200')
printer.lf()
printer.text('1234567890123456789012345678901234567890123456789012345678901234567890')
printer.printAreaWidth()
printer.lf()

Rotate text 90 degrees

Rotate all text 90 degrees

printer.rotate90(100)
printer.text('This text is rotated 90 degrees')

Set tab positions

Set tab positions. This is useful in combination with tab() for printing out receipts with plus, quantities and prices.

printer.tabPositions([3, 32])
for plu in plus:
    printer.text(plu.quantity)
    printer.tab()
    printer.text(' x ' + plu.name)
    printer.tab()
    printer.text('$' + plu.price)

"""
2  x Guinness                  $12.00
3  x Margharita Pizza          $45.00
10 x Coke                      $25.00
2  x Tandoori Chicken          $40.00
"""

Underline

Underline text.

printer.underline()
printer.text('This text is underlined text')
printer.lf()
printer.underline(True,True)
printer.text('This text is double dot width underlined text')
printer.lf()
printer.underline(False)
printer.text('This text is not underlined')
printer.lf()

Set horizontal position

Set horizontal printing position.

printer.horizontalPosition(100)
printer.text('This text starts at 1/6inches from left margin')

Cut paper

Cut the paper using the paper cutter(Only for models with cutter)

printer.cutPaper()

Open cash drawer

Sends a electric pulse on close contact interface. Usually connected to a cash drawer for opening the drawer.

printer.drawerKickPulse()

To run the commands first you must create a printer object as explained in the previous section

 
File Type Py Version Uploaded on Size
python-printer-escpos-0.0.3.tar.gz (md5) Source 2016-05-23 11KB