Skip to content

Instantly share code, notes, and snippets.

@miracle2k
Last active August 25, 2016 13:10
Show Gist options
  • Save miracle2k/f12969c76cc16dc13ea69c1098866d4b to your computer and use it in GitHub Desktop.
Save miracle2k/f12969c76cc16dc13ea69c1098866d4b to your computer and use it in GitHub Desktop.
Python ESC/POS tests
# coding: utf-8
#
# Usage: python printbon.py | lp -d EPSON_TM-P2.01
from escpos import printer
from escpos.constants import FS
Epson = printer.Dummy()
# Set the defaults
Epson.set()
# Experiment with charcodes
Epson.charcode('EURO')
#Epson._raw('\xB5')
#Epson.charcode('USA')
Epson._raw('\x1b3%s' % chr(10))
Epson._raw('\xC9{}\xBB'.format('\xCD' * 40))
for x in range(1, 20):
if x == 5:
Epson._raw('\xBA{}'.format(' ' * 20))
Epson.set(height=2)
Epson._raw('1234\x5D')
Epson._raw('{}\xBA'.format(' ' * 15))
else:
Epson._raw('\xBA{}\xBA'.format(' ' * 40))
Epson._raw('\xC8{}\xBC'.format('\xCD' * 40))
# Epson.set('center', width=3, height=2)
# Epson.text("My favorite\n person!\n")
# Epson.image('/Users/michael/Desktop/a.png')
# Experiment with CR
# Epson.text(u"Before CR")
# Epson.control('LF')
# Epson.set("CENTER")
# Epson.text("-> Should center\n")
### BTabs
# Epson.text("\n\n\n")
# Epson.text(u"1234567890\n")
# Epson.text(u"1234567890\n")
# Epson.control('HT', pos=[2,6,16, 18, 27])
# Epson.text(u"\tabcd\tb\tc\td\te\tfsdf\t545454545 UUU\n")
# Epson.text(u"foo\ta1\tgg\tee\n")
# Epson.text(u"Hello World\n")
### Images
#Epson.image('/Users/michael/Desktop/test.png', high_density_vertical=False, high_density_horizontal=True)
# Epson.text('before')
# Epson._raw(FS + 'p10')
# Epson.text('after')
### Columns
#Epson.text("testsadf asdf sdfkjasdf asdkfjhads fkhjasdlf kahsdfk asdfkhals dfkh")
### Barcode
#Epson.text("\n\n\n\n")
#Epson.barcode('1324354657687','EAN13',64,2,'','')
# Epson.set(width=6, height=4)
# Epson.text("My Cafe")
# Epson.text('\n')
# Epson.text('\n')
#Epson.barcode('{B012ABCDabcdsdfsdfdfdf', 'code128', function_type='B', width=2)
### XML
from xmlescpos import Layout
# support we need:
layout = Layout(u"""
<receipt>
<line width="56" font="b">
<left>Johannesstrasse</left>
<right>25.01.2015</right>
</line>
<!--<line width="42" font="a">
<left>Johannesstrasse</left>
<right>25.01.2015</right>
</line>-->
<br />
<h4>Delivery #123</h4>
<br />
<p>Michael Elsdörfer</p>
<p>Am Wald 4</p>
<p>85077 Manching</p>
<br />
<line width="56" font="b" size="double-height">
<left>1x [456] Suppe</left>
<right size="normal">0.15 E</right>
</line>
<p width="56" font="b" >
Rote Vanille Sauce
Nicht zu heiss.
</p>
<br />
<line width="56" font="b" size="double-height">
<left>1x [456] Suppe</left>
<right size="normal">0.15 E</right>
</line>
<p width="56" font="b" >
Rote Vanille Sauce
Nicht zu heiss.
</p>
<br />
<hr width="42" />
<br />
<line width="42" size='double-height'>
<left>TOTAL</left>
<right>0.15</right>
</line>
</receipt>
""")
layout.format(Epson)
Epson.cut()
# Ouput
code = Epson.output
print code
import sys
for line in code.splitlines():
sys.stderr.write('%s\n' % repr(line))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment