A simple tool for printing to thermal printers.
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 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.
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.
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
turn on or off bold
turn on or off upside-down mode
turn on or off invert (white on black)
set underline thickness:
0 - none (default)
1 - thin
2 - think
print and feed n lines or m dots
set line spacing to n dots - defaults to 32
set left margin to n dots - defaults to 0
set text alignment
make a barcode with specified DATA
a barcode will only print if it will fit on the paper
type | length | characters |
---|---|---|
UPC-A | 11, 12 | 0-9 |
UPC-E | 11, 12 | 0-9 |
EAN13 | 12, 13 | 0-9 |
EAN8 | 7, 8 | 0-9 |
CODE39 | >1 | 0-9, A-Z, +, SPACE, $, % |
I25 | even | 0-9 |
CODEBAR | >1 | 0-9, A-Z, +, SPACE |
CODE93 | >1 | any |
CODE128 | >1 | any |
CODE11 | >1 | 0-9 |
MSI | >1 | 0-9 |
set height to n dots - defaults to 50
set width - defaults to 2
set location of "human readable" text
set left space, in dots
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.
same as image, but rotates the image 90 degrees to the right - useful for printing long things in "landscape".
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)
"Set printing density"
n - printing density = .5+.05*n
m - printing break time = 250us*m
clears the buffer and resets everything
print the testpgage, with the current code table and status
select character set n (see manual)
Set the current Code Table.
n | Code 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] |
10 | Iran |
11 | reserve |
12 | reserve |
13 | reserve |
14 | reserve |
15 | CP862[Hebrew] |
16 | WCP1252[Latin I] |
17 | WCP1253[Greek] |
18 | CP852[Latina 2] |
19 | CP858(Multilingual Latin I +Euro |
20 | Iran II |
21 | Latvian |
22 | CP864[Arabic] |
23 | ISO-8859-1[West Europe] |
24 | CP737[Greek] |
25 | WCP1257[Baltic] |
26 | Thai |
27 | CP720[Arabic] |
28 | CP855 |
29 | CP857[Turkish] |
30 | WCP1250[Central Europe] |
31 | CP775 |
32 | WCP1254[Turkish] |
33 | WCP1255[Hebrew] |
34 | WCP1256[Arabic] |
35 | WCP1258[Vietnam] |
36 | ISO-8859-2[Latin 2] |
37 | ISO-8859-3[Latin 3] |
38 | ISO-8859-4[Baltic] |
39 | ISO-8859-5[Cyrillic] |
40 | ISO-8859-6[Arabic] |
41 | ISO-8859-7[Greek] |
42 | ISO-8859-8[Hebrew] |
43 | ISO-8859-9[Turkish] |
44 | ISO-8859-15[Latin 3] |
45 | Thai2 |
46 | CP856 |
47 | Cp874 |