From /

Raw printing

A few months a go, I got a 1990s dot matrix printer and later a small receipt printer. I was struck by the simple way in which you can print using these descendants of line printers.

Like line printers these two types of printers perform raw printing or line mode printing. In raw printing the printer does not interpret a description of the forms to draw, such as in page description language (PDLs) like PostScript and Page Command Language (PDL), to draw those shapes onto paper, as is the case of current laser and inkjet printers. Instead in raw printing plain-text characters are send to the printer and outputted by the printer in the sequence they are received, one line at a time. In practical terms, the command echo "Hello Printer" > /dev/usb/lp0 will result in "Hello Printer" being printed. What is happening inside the operating system (if you are not using MS Windows) is the sequence of characters "Hello Printer" is being written to the file (in Unix-like system everything is a file) representing to the printer in your operating system /dev/usb/lp0 .

Keep in mind that lp0 might appear under a different device. For instances, if the printer is connected to the serial port lp0 will appear under /dev/serial/. And if you have more than one printer connect to your system you'll see not only lp0, but also lp1, lp2.

Common Raw Printing Languages

The simplicity of raw printing has its shortcomings. You can easily print ASCII characters, but what if you want print large titles, or words in bold, or other character sets than ASCII, or even images? In raw printing you these style options, require the state of the printer to be change, you have to tell it:

Great printer, 
goddess of ink and paper, 
machine of great noises,
queen of the office,
you'll now print in bold?
and rotate those letter 90°?

However all those invocations and and instructions have to be expressed in a language that the printer understands, tje raw printing language of that printer.


One popular raw printing languages is ESC/POS, which stands for Epson Standard Code.

  • adoption by other manufacturers
  • variations: there are some variations of ESC/POS commands for different printers.

The best is resort to the manual of the printer at hand. It will describe what commands the printer interprets.

In Epson's document FAQ about ESC/POS the command to turn on/off the underline mode is: File:Epson Manual p4.png

Hex 1B 2D n
n is 0 turns underline off
n is 1 turns underline on, with 1-dot width
n is 2 turns underline on, with 2-dot width

If I consult the list of ESC POS Commands supported by by the USB PHX5 Model printer, to find commands for my receipt printer, I notice that the command for underlining text is the same, however this set of commands has only 1-dot strike option, which can be obtained with n as 0 or as 30.

Control Characters

ESC/POS commands descend from control or non-printing characters, that represent not a visible glyph, but a modification on the printed or displayed text. In the ASCII table the control characters are present in its first values and are used frequently by anyone who uses a computer keyboard.

By pressing the tab key I am typing the ASCII character 11, that happens to be an instruction to tab.

We can also instruct our operating system to perform these modification, by writing using backslash escapes and telling the echo command to interpret them by using the argument -e According to man page of the echo command:

       If -e is in effect, the following sequences are recognized:

       \\     backslash

       \a     alert (BEL)

       \b     backspace

       \c     produce no further output

       \e     escape

       \f     form feed

       \n     new line

       \r     carriage return

       \t     horizontal tab

       \v     vertical tab

       \0NNN  byte with octal value NNN (1 to 3 digits)

       \xHH   byte with hexadecimal value HH (1 to 2 digits)

This mean horizontal tabbing can be accomplished by

echo -e "\tA"


"A" appears tabbed in the terminal, since it is preceded by \t, or vertically tabbed if instead \v is used.

origin of control characters


control characters for raw printing

problem with TAB, cannot find it in manuals.
how did I find out the Tab hex value x\09 ? 
use tab as example
return to underline later.

At the end of echo man page of shown above, there is the "byte with hexadecimal value". This is the format in which most printers receive control characters.

an horizontal tab 09. If I send this value to the printer, followed by a string: echo -e "\x09 I am being tabbed" > /dev/usb/lp0 the printer will print "I am being tabbed" tabbed to the right.

By consulting once more list of ESC POS commands , I can find the hexadecimal value that performs

1B 2D n
On: $00, $30
Off: $01, $31  

Just to make it clear, 1-dot underline printing will be activated by the command:

echo -e "\x1B\x2D\x01" > /dev/usb/lp0


printing images with ESC/POS

(is it a sequence of character the most appropriate name?)

???Curiously \e is an escape control character, which initiates a "control sequence" or "escape sequence".

ESP/POS derives from the control characters,

Wikipidia ASCII code 27 (escape), followed by a series of characters called a "control sequence" or "escape sequence"