Receipt Markup Language

A simple tool for printing to thermal printers.

Thermal Printer

The device in question is "[Mini] Thermal Printer", available from Sparkfun and Adafruit.

It's a relatively cheap receipt printer that can print text, barcodes, and images on 2.25 inch thermal paper.

It provides a simple command set for changing text attributes and performing special functions.

As far as I could tell, there was no easy way to print to it from a computer, so I made a tool for that.

rml.py

rml.py is a python script that reads a file and sends it to the printer.

It also looks for special commands. The commands form a simple markup language i'm calling Receipt Markup Language.

The script can be used in several ways. Input is read either from a file, when specified, or from stdin (typed directly into the terminal or piped from another source). Similarly, output is written either directly to a device when a port is specified, or to stdout (ends up in the terminal if not piped away).

A few nonstandard Python libraries are used: The Python Imaging Library and pySerial.

Download rml.py on GitHub.

RML Commands

RML commands are wrapped in curly braces {like so}.

The first word is the name of the command, and following words are arguments.

Any unrecognized command is ignored, though {# bla bla} is as good a comment syntax as any.

Anything outside a command is sent directly to the printer.

When a line is printed, all current settings are used. Anything set before the end of the line is applied to the whole line (and following lines). This means that, as far as I can tell, a style can't apply to only part of a line.

Character Styles

{style [tall | big] [inv] [ud] [em] [strike]} ESC !

Set size, invert, updown, em, and strike.
tall - double height
big - double height and width
inv - inverted (white on black)
ud - upside-down
em - "emphasized" - this might be the same as bold
strike- "deleteline", a strange double-strikethrough effect

{b} {/b} ESC E

turn on or off bold

{ud} {/ud} ESC {

turn on or off upside-down mode

{inv} {/inv} ESC B

turn on or off invert (white on black)

{u [0 | 1 | 2]} ESC -

set underline thickness:
0 - none (default)
1 - thin
2 - think

Formatting and Layout

{feedL n} {feedD m} ESC J, ESC d

print and feed n lines or m dots

{lineSpace n} ESC 3

set line spacing to n dots - defaults to 32

{leftSpace n} GS L

set left margin to n dots - defaults to 0

{left} {center} {right} ESC a

set text alignment

Barcodes

{barcode TYPE DATA} GS k

make a barcode with specified DATA
a barcode will only print if it will fit on the paper
typelengthcharacters
UPC-A11, 120-9
UPC-E11, 120-9
EAN1312, 130-9
EAN87, 80-9
CODE39>10-9, A-Z, +, SPACE, $, %
I25even0-9
CODEBAR>10-9, A-Z, +, SPACE
CODE93>1any
CODE128>1any
CODE11>10-9
MSI>10-9

{bcH n} GS h

set height to n dots - defaults to 50

{bcW [2|3]} GS w

set width - defaults to 2

{bcLoc [above] [below]} GS H

set location of "human readable" text

{bcSpace n} GS w

set left space, in dots

Image

{image FILE} GS v

prints the image FILE.
Images narrower than 384px will be rounded up the the nearest multible of 8, larger images will be scaled down.
Accepts most common image formats, though for best results, scale images and convert to black and white (not greyscale) with your favorite image editor.

{imageR FILE} GS v

same as image, but rotates the image 90 degrees to the right - useful for printing long things in "landscape".

Printing Parameters

{heat n m k} ESC 7

printing heat and timing settings
n - max printing dots - unit(8) - default to 7 (64 dots)
m - heating time - unit(10us) - default to 80 (800us)
k - heating interval - unit(10us) - defaults to 2 (20us)

{density n m} DC2 #

"Set printing density"
n - printing density = .5+.05*n
m - printing break time = 250us*m

Other

{init} ESC @

clears the buffer and resets everything

{testpage} DC2 T

print the testpgage, with the current code table and status

{charset n} ESC R

select character set n (see manual)

{codetable n} ESC t

Set the current Code Table.

nCode Page
0 CP437[U.S.A., Standard Europe]
1 Katakana
2 CP850[Multilingual]
3 CP860[Portuguese]
4 CP863[Canadian-French]
5 CP865[Nordic]
6 CP1251[Cyrillic]
7 CP866 Cyrilliec #2
8 MIK[Cyrillic /Bulgarian]
9 CP755[East Europe, Latvian 2]
10Iran
11reserve
12reserve
13reserve
14reserve
15CP862[Hebrew]
16WCP1252[Latin I]
17WCP1253[Greek]
18CP852[Latina 2]
19CP858(Multilingual Latin I +Euro
20Iran II
21Latvian
22CP864[Arabic]
23ISO-8859-1[West Europe]
24CP737[Greek]
25WCP1257[Baltic]
26Thai
27CP720[Arabic]
28CP855
29CP857[Turkish]
30WCP1250[Central Europe]
31CP775
32WCP1254[Turkish]
33WCP1255[Hebrew]
34WCP1256[Arabic]
35WCP1258[Vietnam]
36ISO-8859-2[Latin 2]
37ISO-8859-3[Latin 3]
38ISO-8859-4[Baltic]
39ISO-8859-5[Cyrillic]
40ISO-8859-6[Arabic]
41ISO-8859-7[Greek]
42ISO-8859-8[Hebrew]
43ISO-8859-9[Turkish]
44ISO-8859-15[Latin 3]
45Thai2
46CP856
47Cp874



{home}