Printer Codes
=============

This document summarises common control codes and escape sequences, as employed
in older dot-matrix printers. There is considerable variation in the exact
interpretation of such codes, but unless indicated otherwise they work with
both Epson (ESC/P) printers and IBM-compatible printers. Other printer models
may use some of these sequences or different codes of their own.

The notation for escape sequences is quite simple. For example, the instruction
ESC ! BS consists of ESC (code 27) followed by ! (code 33) and BS (code 8).


==============================================================================
Standard Control Codes
==============================================================================

* Indicates standard ASCII code whose function can vary.

Dec Cmd Effect                                                    Printer Type
------------------------------------------------------------------------------
0   NUL Null *
1   SOH Start of heading *
2   STX Start of text *
3   ETX End of text *
4   EOT End of transmission *
5   ENQ Enquiry *
6   ACK Acknowledge *
7   BEL Sounds printer bell or buzzer
8   BS  Back Space
9   HT  Horizontal Tabulation
10  LF  Line feed
11  VT  Vertical Tabulation
12  FF  Form Feed
13  CR  Carriage Return
14  SO  Shift out: Select enlarged (double-width) printing
        for one line. Cancelled by CR (or DC4 if sooner).
15  SI  Shift in: Select condensed printing (fine print, 17.1 cpi)         IBM
------------------------------------------------------------------------------
16  DLE Data link escape *
17  DC1 Device control 1: Enable printer (print suppress mode off)       ESC/P
------------------------------------------------------------------------------
18  DC2 Device control 2: Select pica print (10 cpi)                     ESC/P
18  DC2 Device control 2: Cancel condensed printing                        IBM
------------------------------------------------------------------------------
19  DC3 Device control 3: Disable printer (print suppress mode on)       ESC/P
20  DC4 Device control 4: Cancel enlarged (double-width)
        printing if set by SO but not if enabled by ESC W or ESC !       ESC/P
21  NAK Not Acknowledge *
22  SYN Synchronous idle *
23  ETB End of transmission block *
24  CAN Cancel: cancel preceding line in printer buffer
25  EM  End of medium *
26  SUB Substitute *
27  ESC Escape (see sequences below)
------------------------------------------------------------------------------
28  FS  File separator *
29  GS  Group separator *
30  RS  Record separator *
31  US  Unit separator *
------------------------------------------------------------------------------


==============================================================================
Escape Sequences
==============================================================================

• Indicates Epson escape code that accepts either NUL (0) or ASCII ‘0’ for OFF,
  similarly SOH (1) or ASCII ‘1” for ON.

ESC Sequence             Effect                                    Printer Type
------------------------------------------------------------------------------
27 0        ESC NUL      Undefined
27 1        ESC SOH      Undefined
27 2        ESC STX      Undefined
27 3        ESC ETX      Undefined
27 4        ESC EOT      Undefined
27 5        ESC ENQ      Undefined
27 6        ESC ACK      Undefined
27 7        ESC BEL      Undefined
27 8        ESC BS       Undefined
27 9        ESC HT       Undefined
27 10       ESC LF       Undefined
27 11       ESC VT       Undefined
27 12       ESC FF       Undefined
27 13       ESC CR       Undefined
27 14       ESC SO       Undefined
27 15       ESC SI       Condensed printing on (fine print, 17.1 cpi)
------------------------------------------------------------------------------
27 16       ESC DLE      Undefined
27 17       ESC DC1      Undefined
27 18       ESC DC2      Undefined
27 18       ESC DC2      Undefined
27 19       ESC DC3      Undefined
27 20       ESC DC4      Undefined
27 21       ESC NAK      Undefined
27 22       ESC SYN      Undefined
27 23       ESC ETB      Undefined
27 24       ESC CAN      Undefined
------------------------------------------------------------------------------
27 25 0     ESC EM NUL   Cut Sheet Feeder (CSF) off                      ESC/P
27 25 49    ESC EM 1     Cut Sheet Feeder (CSF) bin 1 select
27 25 50    ESC EM 2     Cut Sheet Feeder (CSF) bin 2 select
27 25 73    ESC EM I     Cut Sheet Feeder (CSF) single sheet insert        IBM
27 25 82    ESC EM R     Cut Sheet Feeder (CSF) single sheet eject         IBM
------------------------------------------------------------------------------
27 26       ESC SUB      Undefined
27 27       ESC ESC      Undefined
27 28       ESC FS       Undefined
27 29       ESC GS       Undefined
27 30       ESC RS       Undefined
27 31       ESC US       Undefined
------------------------------------------------------------------------------
27 32 nn    ESC SP nn    Add nn to inter-character spacing               ESC/P
------------------------------------------------------------------------------
27 33 0     ESC ! NUL    Master style: pica                              ESC/P
27 33 1     ESC ! SOH    Master style: elite                             ESC/P
27 33 2     ESC ! STX    Master style: proportional                      ESC/P
27 33 4     ESC ! EOT    Master style: condensed                         ESC/P
27 33 8     ESC ! BS     Master style: emphasised                        ESC/P
27 33 16    ESC ! DLE    Master style: enhanced (double-strike)          ESC/P
27 33 32    ESC ! SP     Master style: enlarged (double-width)           ESC/P
27 33 64    ESC ! @      Master style: italic                            ESC/P
27 33 128   ESC ! ---    Master style: underline                         ESC/P
                         Above values can be added for combined styles.
------------------------------------------------------------------------------
27 33 64   ESC ! @
to         to
27 33 81   ESC ! Q       Select character set (@ gives ASCII)              IBM
------------------------------------------------------------------------------
27 34      ESC "         Undefined
------------------------------------------------------------------------------
27 35      ESC #         Use bit 8 of received input data, overriding
                         ESC = or ESC > commands                         ESC/P
27 35 48   ESC # 0       Draft mode                                        IBM
------------------------------------------------------------------------------
27 36 n1 n2              Set absolute dot position to n1+(n2*256) in
           ESC $ n1 n2   60th of inch                                    ESC/P
27 36      ESC $         Copy standard character set to down-line
                         loadable (DLL) character generator (CG)           IBM
------------------------------------------------------------------------------
27 37 0    ESC % NUL     • User-defined character set off                ESC/P
27 37 1    ESC % SOH     • User-defined character set on                 ESC/P
27 37 65 m n1...n11      Load down-line loadable (DLL) ascender            IBM
           ESC % A m n1...n11
27 37 66 m n1...n4       Indent print position by dot position n1...n4     IBM
           ESC % B m n1...n4
27 37 68 m n1...n11      Load down-line loadable (DLL) descender           IBM
           ESC % D m n1...n11
27 37 71   ESC % G       Italic printing on                                IBM
27 37 72   ESC % H       Italic printing off                               IBM
27 37 80   ESC % P       Proportional spacing on                           IBM
27 37 81   ESC % Q       Proportional spacing off                          IBM
27 37 89   ESC % Y       Designate down-line loadable (DLL) as utility
                         character set                                     IBM
27 37 90   ESC % Z       Designate down-line loadable (DLL) as quasi-NLQ   IBM
------------------------------------------------------------------------------
27 38 0 d0 d1 data…      Define user-defined characters from ASCII
           ESC & d0 d1 data…                         code d0 to d1       ESC/P
27 39      ESC '         Undefined
27 40      ESC (         High speed draft (HSD) mode                     ESC/P
27 41      ESC )         Undefined
27 42 mm n1 n2 data…     Generate 8-pin bit-image of quality set by mm.
           ESC * mm n1 n2 data…  Some Epson devices use simpler system
                         with mm set to 4, 5 or 6 for 80, 72 or 90 dpi.  ESC/P
27 43      ESC +         Undefined
27 44      ESC ,         Undefined
------------------------------------------------------------------------------
27 45 48   ESC - 0       Underlining off
27 45 49   ESC - 1       Underlining on
------------------------------------------------------------------------------
27 46      ESC .         Undefined
27 47 cc   ESC / cc      Select vertical tab channel for future VT
                         commands (cc = 0 - 7)                           ESC/P
------------------------------------------------------------------------------
27 48      ESC 0         8 lpi line spacing (1/8 inch)
27 49      ESC 1         10.2 lpi line spacing (7/72 inch)
------------------------------------------------------------------------------
27 50      ESC 2         6 lpi line spacing (1/6 inch)                   ESC/P
27 50      ESC 2         Activate programmable line spacing as set
                         by ESC A                                          IBM
------------------------------------------------------------------------------
27 51 nn   ESC 3 nn      Select nn/216 inch line spacing
------------------------------------------------------------------------------
27 52      ESC 4         Italic characters on                            ESC/P
27 52      ESC 4         Set top of form to current print head position    IBM
------------------------------------------------------------------------------
27 53      ESC 5         Italic characters off                           ESC/P
27 53 48   ESC 5 0       Automatic LF after CR off                         IBM
27 53 49   ESC 5 1       Automatic LF after CR on                          IBM
------------------------------------------------------------------------------
27 54      ESC 6         Permit printing ASCII codes 128-159 and 255     ESC/P
27 54      ESC 6         Select IBM character set 2 (World Trade)          IBM
------------------------------------------------------------------------------
27 55      ESC 7         Prevent printing ASCII codes 128-159 and 255    ESC/P
27 55      ESC 7         Select IBM character set 1                        IBM
------------------------------------------------------------------------------
27 56      ESC 8         Disable paper-out detector
27 57      ESC 9         Enable paper-out detector
------------------------------------------------------------------------------
27 58 0 0 0              Copy character ROM to user-defined characters   ESC/P
           ESC : NUL NUL NUL
27 58      ESC :         Select elite print (12 cpi)                       IBM
------------------------------------------------------------------------------
27 59      ESC ;         Undefined
------------------------------------------------------------------------------
27 60      ESC <         Unidirectional printing for one line            ESC/P
27 60      ESC <         Home head                                         IBM
------------------------------------------------------------------------------
27 61      ESC =         Set bit 8 of incoming data to 0
                         (all characters non-italic)                     ESC/P
27 62      ESC >         Set bit 8 of incoming data to 1
                         (all characters italic)                         ESC/P
------------------------------------------------------------------------------
27 63 75 mm              Reassign 8-pin bit image command ESC K to
           ESC ? K mm    mode mm (see ESC *)                             ESC/P
27 63 76 mm              Reassign 8-pin bit image command ESC L to
           ESC ? L mm    mode mm (see ESC *)                             ESC/P
27 63 89 mm              Reassign 8-pin bit image command ESC Y to
           ESC ? Y mm    mode mm (see ESC *)                             ESC/P
27 63 90 mm              Reassign 8-pin bit image command ESC Z to
           ESC ? Z mm    mode mm (see ESC *)                             ESC/P
------------------------------------------------------------------------------
27 64      ESC @         Initialise printer with default tabs            ESC/P
27 65 nn   ESC A nn      Select nn/72 line spacing
                         (ESC 2 must follow for IBM printer)
------------------------------------------------------------------------------
27 66 n1 n2 … 0          Set vert tabs, n1, n2 …, 1 to 255 in ascending order
           ESC B n1 n2 … NUL                         
27 66 0    ESC B NUL     Cancel above tab settings
27 67 nn   ESC C nn      Set page length to nn lines
27 67 0 nn ESC C NUL nn  Set page length to nn inches
------------------------------------------------------------------------------
27 68 n1 n2 … 0          Set horizontal tabs in ascending order
           ESC D n1 n2 … NUL
27 68 0    ESC D NUL     Cancel above tab settings
27 69      ESC E         Emphasised (bold) printing on
                         (overprinted with sideways shift)
27 70      ESC F         Emphasised (bold) printing off
27 71      ESC G         Double-strike printing on
                         (overprinted after 1/216 inch line feed)
27 72      ESC H         Double-strike printing off
------------------------------------------------------------------------------
27 73 48   ESC I 0       • Use codes 0-31 and 128-159 as control codes   ESC/P
27 73 48   ESC I 0       Utility mode                                      IBM
27 73 49   ESC I 1       • Use codes 0-31 and 128-159 as characters      ESC/P
27 73 49   ESC I 1       Utility mode                                      IBM
27 73 50   ESC I 2       NLQ mode                                          IBM
27 73 51   ESC I 3       NLQ mode                                          IBM
------------------------------------------------------------------------------
27 74 nn   ESC J nn      Perform nn/216 inch line feed.
                         Acts as CR if nn = 0
27 75 n1 n2 data…        Single density bit-image, often 60 dpi,
           ESC K n1 n2 data…   (same as ESC * NUL) or as defined by ESC ?
27 76 n1 n2 data…        Double density bit-image, often 120 dpi,
           ESC L n1 n2 data…   (same as ESC * SOH) or as defined by ESC ?
27 77      ESC M         Select elite print (12 cpi)                     ESC/P
27 78 nn   ESC N nn      Set bottom margin to nn lines
27 79      ESC O         Set bottom margin to zero lines
------------------------------------------------------------------------------
27 80      ESC P         Select pica print (10 cpi)                      ESC/P
27 80 48   ESC P 0       Proportional spacing off                          IBM
27 80 49   ESC P 1       Proportional spacing on                           IBM
------------------------------------------------------------------------------
27 81 nn   ESC Q nn      Set right margin to nn columns of
                         character width                                 ESC/P
27 81 3    ESC Q ETX     Disable printing                                  IBM
27 81 22   ESC Q SYN     Disable printing                                  IBM
------------------------------------------------------------------------------
27 82 0    ESC R NUL
to         to
27 82 20   ESC R DC4     Select international character set              ESC/P
27 82      ESC R         Restore default tab settings                      IBM
------------------------------------------------------------------------------
27 83 48   ESC S 0       • Superscript on
27 83 49   ESC S 1       • Subscript on
------------------------------------------------------------------------------
27 84      ESC T         Superscript/Subscript off
------------------------------------------------------------------------------
27 85 48   ESC U 0       • Unidirectional mode off
27 85 49   ESC U 1       • Unidirectional mode on
------------------------------------------------------------------------------
27 86 0    ESC V NUL     Standard character spacing
27 86 nn   ESC V nn      Change character spacing by nn
------------------------------------------------------------------------------
27 87 48   ESC W 0       • Enlarged (double-width) printing off
27 87 49   ESC W 1       • Enlarged (double-width) printing on
------------------------------------------------------------------------------
27 88 nn mm              Set left margin to nn, right margin to mm         IBM
           ESC X nn mm 
27 89 n1 n2 data…        High speed double density bit-image
           ESC Y n1 n2 data…         (as ESC * STX) or as defined by ESC ?
------------------------------------------------------------------------------
27 90 n1 n2 data…        High speed quad density bit-image, often 240 dpi
           ESC Z n1 n2 data…         (as ESC * ETX) or as defined by ESC ?
27 91 64 n1 n2 m1… m4    Begin double-height or double-width printing as
           ESC [ @  n1 n2 m1… m4     specified in data                     IBM
------------------------------------------------------------------------------
27 92 n1 n2              Set relative dot position to n1+(n2*256)
           ESC \ n1 n2   in 120th of inch                                ESC/P
27 92 n1 n2 …            Print continuously from all-character set         IBM
           ESC \ n1 n2 …
------------------------------------------------------------------------------
27 93      ESC ]         Reverse line feed                                 IBM
------------------------------------------------------------------------------
27 94 0 n1 n2 data…      Single density 9-pin bit-image                  ESC/P
           ESC ^ NUL n1 n2 data…
27 94 1 n1 n2 data…      Double density 9-pin bit-image                  ESC/P
           ESC ^ SOH n1 n2 data…
27 94 n    ESC ^ n        Print one character from all-character set       IBM
------------------------------------------------------------------------------
27 95 48   ESC _ 0       Over-scoring off
27 95 49   ESC _ 1       Over-scoring on
------------------------------------------------------------------------------
27 96      ESC `         Undefined
------------------------------------------------------------------------------
27 97 0    ESC a NUL     NLQ left justification                          ESC/P
27 97 1    ESC a SOH     NLQ centre justification                        ESC/P
27 97 2    ESC a STX     NLQ right justification                         ESC/P
27 97 3    ESC a ETX     NLQ full or fill justification                  ESC/P
------------------------------------------------------------------------------
27 98 cc n1 n2 … 0       Set vertical tabs in channel cc, with tab
           ESC b  cc n1 n2 … NUL   positions n1, n2… in ascending order  ESC/P
27 99      ESC c         Undefined
27 100     ESC d         Undefined
------------------------------------------------------------------------------
27 101 0   ESC e NUL     Set horiz tab increment (not all printers)      ESC/P
27 101 1   ESC e SOH     Set vertical tab increment (not all printers)   ESC/P
27 102 0   ESC f NUL     Horizontal skip (not all printers)              ESC/P
27 102 1   ESC f SOH     Vertical skip (not all printers)                ESC/P
------------------------------------------------------------------------------
27 103     ESC g         Undefined
27 104     ESC h         Undefined
------------------------------------------------------------------------------
27 105 0   ESC i NULL    • Typewriter mode off                           ESC/P
27 105 1   ESC i SOH     • Typewriter mode on                            ESC/P
------------------------------------------------------------------------------
27 106 nn  ESC j nn      Perform nn/216 inch reverse line feed           ESC/P
27 107     ESC k         Select font family (not all printers)           ESC/P
27 108 nn  ESC l nn      Set left margin to nn columns of current
                         character width                                 ESC/P
27 109     ESC m         Select special graphics characters
                         (not all printers)                              ESC/P
27 110     ESC n         Undefined
27 111     ESC o         Undefined
------------------------------------------------------------------------------
27 112 48  ESC p 0       • Proportional spacing off                      ESC/P
27 112 49  ESC p 1       • Proportional spacing on                       ESC/P
------------------------------------------------------------------------------
27 113     ESC q         Undefined
27 114     ESC r         Undefined
------------------------------------------------------------------------------
27 115 48  ESC s 0       Half-speed mode off                             ESC/P
27 115 49  ESC s 1       Half-speed mode on                              ESC/P
------------------------------------------------------------------------------
27 116 0   ESC t NUL     Normal Epson character set                      ESC/P
27 116 1   ESC t SOH     Line graphics Epson character set               ESC/P
------------------------------------------------------------------------------
27 117     ESC u         Undefined
27 118     ESC v         Undefined
------------------------------------------------------------------------------
27 119 48  ESC w 0       Double-height off                               ESC/P
27 119 49  ESC w 1       Double-height on                                ESC/P
------------------------------------------------------------------------------
27 120 0   ESC x NUL     • Draft mode                                    ESC/P
27 120 1   ESC x SOH     • NLQ mode                                      ESC/P
------------------------------------------------------------------------------
27 121     ESC y         Undefined
27 122     ESC z         Undefined
27 123     ESC {         Undefined
27 124     ESC |         Undefined
27 125     ESC }         Undefined
27 126     ESC ~         Undefined
27 127     ESC DEL       Undefined
------------------------------------------------------------------------------