Epson Printer ESC/P2 codes

  • Code 
  • Purpose 
  • Details 
    • General Operation 
    • ESC @ 
  • reset 
  •  
    • ESC U 
  • unidirectional on/off 
  •  
    • ESC EM n 
  • cut sheet feeder operation 
  • n = 0 Disable CSF  

  • n = 1 Select Bin 1 
    n = 2 Select Bin 2 
    n = 4 Enable CSF 
    n = R Eject Sheet
    • ESC s 
  • half speed on/off 
  •  
    • Paper feeding 
    • CR 
  • Prints buffer contents and resets buffer count to 0 
  •  
    • FF 
  • Advances paper to next logical TOF (top of form) 
  •  
    • LF 
  • Printer empties its buffer and does line feed at current line spacing and resets buffer pointer to zero. 
  •  
    • ESC 0 
  • 8 lines per inch 
  • reset perforation skip to 0 lines 
    • ESC 2 
  • single-space text (6 lines per inch) 
  •  
    • ESC 3 n 
  • line spacing 
  • n/180-inch  

  • n/216-inch
    • ESC A n 
  • line spacing 
  • n/60-inch  

  • n/72-inch
    • ESC + n 
  • line spacing 
  • n/360-inch 
    • ESC \065\020 
  • double-space text (3 lines per inch) 
  •  
    • Page format 
    • ESC i n 
  • Immediate mode on/off 
  •  
    • ESC ( C m1 m2 n1 n2 
  • Set Page Length in Defined Units 
  • ESC ( C m1 m2 n1 n2 is the command for setting the page length in units where m1, m2, n1 and n2 are variables. The "unit" is usually 1/360 of an inch unless defined otherwise by the "ESC ( U" command. Currently, the values for m1 and m2 MUST be m1=2 and m2=0.  

  • To determine the values for n1 and n2 perform the following steps. 
    1. Determine the desired page length in inches. 
    2. Multiply the page length by 360. 
    3. Divide the result by 256 using long division. 
    4. The remainder in the quotient from step 3 is the value for n1. 
    5. The whole number in the quotient from step 3 is the value for n2. 
    EXAMPLE 
    1. The page length is 8.5 inches. 
    2. 8.5 x 360 = 3060 
    3. 3060 divided by 256 = 11 with a remainder of 244. 
    4. n1=244 
    5. n2=11
    • ESC C n 
  • page length in lines 
  •  
    • ESC C NUL n 
  • page length in inches 
  •  
    • ESC Q n 
  • set right margin  
  •  
    • ESC 1 n 
  • set left margin  
  •  
    • ESC ( c 
  • tell me if you know 
  •  
    • ESC N n 
  • skip over perforation  
  •  
    • ESC O 
  • tell me if you know 
  •  
    • ESC SP n 
  • intercharacter spacing  
  •  
    • Print position 
    • ESC V n data 
  • repeat data  
  •  
    • ESC $ n1 n2 
  • set absolute print position  
  •  
    • ESC \ n1 n2 
  • set relative print position  
  •  
    • ESC ( V m1 m2 n1 n2 
  • Set Absolute Vertical Position 
  • ESC ( V m1 m2 n1 n2 is the command for changing the print position vertically (with respect to the Top of Form position) in units where m1, m2, n1 and n2 are variables. The "unit" is usually 1/360 of an inch unless defined otherwise by the "ESC ( U" command. Currently, the values for m1 and m2 MUST be m1=2 and m2=0.  

  • To determine the values for n1 and n2 perform the following steps. 
    1. Determine the desired vertical distance from the Top of Form in inches. 
    2. Multiply the distance by 360. 
    3. Divide the result by 256 using long division. 
    4. The remainder in the quotient from step 3 is the value for n1. 
    5. The whole number in the quotient from step 3 is the value for n2. 
    EXAMPLE 
    1. The desired distance from the Top of Form is 1 inch. 
    2. 1 x 360 = 360 
    3. 360 divided by 256 = 1 with a remainder of 104. 
    4. n1=104 
    5. n2=1 
    • ESC D n1 n2..NUL 
  • horizontal tab stops 
  •  
    • HT 
  • horizontal tab 
  •  
    • ESC e NUL n 
  • horizontal set tab increment 
  •  
    • ESC f NUL n 
  • set horizontal tabs in spaces 
  •  
    • ESC B n1 n2..NUL 
  • vertical tab stops 
  •  
    • ESC b c n1 n2..NUL 
  • set VTabs in channel 
  •  
    • ESC e 1 n 
  • set vertical tab increment 
  •  
    • ESC f 1 n 
  • vertical skip 
  •  
    • VT 
  • vertical tab 
  •  
    • ESC b x n1 n2..NUL 
  • set VFU tab channel 
  •  
    • ESC / x 
  • select VFU tab channel 
  •  
    • ESC / n 
  • set VTab channel 
  •  
    • ESC J n 
  • immediate feed 
  • immediate n/216 feed  

  • immediate n/180 feed
    • ESC j n 
  • reverse feed 
  • reverse feed n/216  

  • reverse feed n/180
    • FONT SELECTION 
    • `ESC k n 
  • select font 
  • n = 1 Roman  

  • n = 1 San Serif 
    n = 2 Courier 
    n = 3 Prestige 
    n = 4 Script 
    n = 5 Ocr-B 
    n = 6 Ocr-A 
    n = 7 Orator (only with mult-font module) 
    n = 8 Orator (only with mult-font module)
    • ESC x0\015 
  • compressed mode 
  • SC600 default is 10cpi...x0\015 results in 17cpi  
    • CPI 

    • 10 
      12 
      15 
      17 
      20
  • COLUMNS  

  • 80 
    96 
    120 
    137 use 10 condensed 
    160 use 12 condensed
  • ESC x1 
  • letter quality mode 
  •  
  •  
    • ESC X m n1 n2 
  • Select Pitch and Point Size 
  • The variable "m" is used to select the pitch, which is the character spacing. The variable "n1" selects the point size and the variable "n2", at this time, will always be 0 (zero).  The variables "m" and "n1" are explained below.   

  • The values used for "m" are 0, 1, 18, 21, 24, 30, 36, 42, 48, 60, and 72. If "0" is used as the value for "m", there will be no change in pitch. If "1" is used as the value for "m", the character pitch will be proportional spacing. To determine the character pitch for all other values of "m", divide 360 by "m". For example, if m=60 then 360 divided by 60 equals 6 and the character pitch is 6 characters per inch. If m=30, the character pitch is 12 characters per inch. 
    For the Roman and Sans Serif fonts, the values used for "n1" are 0, 16, 20, 21, 24, 28, 32, 36, 40, 42, 44, 48, 52, 56, 60 and 64. For all other fonts, the values used for "n1" are 0, 21, and 42. The actual point size that will print is n1 divided by 2. For example, if n1=20, the point size is 10. If n1=48, the point size is 24. 
    NOTE: When selecting a point size larger than 24 (the value for n1 is greater than 48), select proportional spacing (m=1) for the character pitch.

     
    • ESC P 
  • pica pitch (10cpi) 
  •  
  •  
    • ESC M 
  • elite pitch (12cpi) 
  • 20cpi on Stylus Color 600 
  •  
    • ESC g 
  • tiny font in SC600 
  •  
  •  
    • ESC p 
  • proportional on/off 
  •  
  •  
    • ESC 4 
  • italic character set on 
  •  
  •  
    • ESC 5 
  • italic character set off 
  •  
  •  
    • ESC E 
  • emphasized mode (bold) 
  • works with Stylus Color 600 but how to turn offf? 
  •  
    • ESC F 
  • emphasized mode on 
  •  
  •  
    • ESC ! n 
  • master select 
  • n = 0 Pica   

  • n = 1 Elite 
    n = 2 Proportional 
    n = 4 Condensed 
    n = 8 Emphasized 
    n = 16 Double Strike 
    n = 32 Double Wide 
    n = 64 Italic 
    n = 128 Underline
     
    • FONT ENHANCEMENT 
     
    • ESC W 
  • expanded print on/off 
  •  
  •  
    • DC4 
  • Turns off double width mode (shift out only) 
  •  
  •  
    • SO 
  • Turns off double width mode to end of line unless cancelled by DC4 
  •  
  •  
    • DC2 
  • Turns off compressed characters and empties buffer 
  •  
  •  
    • SI 
  • Turns on compressed character mode. 
  • Does not work with emphasized mode. Stays on until cancelled by DC2. 
  •  
    • ESC w 
  • double on/off 
  •  
  •  
    • ESC w\000 
  • expanded mode off 
  •  
  •  
    • ESC w\001 
  • expanded mode on 
  •  
  •  
    • ESC G 
  • double strike on 
  •  
  •  
    • ESC H 
  • double strike, superscript and subscript off 
  •  
  •  
    • ESC T 
  • Resets superscript, subscript, and unidirectional printing 
  • Does not turn off double strike from script modes  

  •  
     
    • ESC S 
  • super/subscript 
  •  
  •  
    • ESC - 
  • underlining on/off 
  •  
  •  
    • ESC -\001 
  • underlining 
  •  
  •  
    • ESC ( - n1 n2 m d1 d2 
  • select score 
  • n1 Must be 3   

  • n2 Must be 0 
    m Must be 1 
    d1 = 1 Underscore 
    d1 = 2 Strike-Through 
    d1 = 3 Overscore 
    d2 = 0 Cancel selected score 
    d2 = 1 Single line continuous 
    d2 = 2 Double Line continuous 
    d2 = 5 Single Line broken 
    d2 = 6 Double Line broken
     
    • ESC q n 
  • character style 
  • n = 0 Normal   

  • n = 1 Outline 
    n = 2 Shadow 
    n = 3 Outline & Shadow
     
    • ESC +(s1 S 
  • italic 
  •  
  •  
    • SPACING 
     
    • ESC Space 
  • Sets character spacing by adding n columns of blank dots between characters.
  • ESC space n
  • n = 0-127 
  • ESC space 40 would put 40 dot spaces between chars l     i    k     e     t    h    i    s     .
  •  
    • ESC c 
  • tell me if you know 
  •  
  •  
    • ESC ( U 
  • tell me if you know 
  •  
  •  
    • CHARACTER HANDLING 
     
    • ESC a n 
  • justification 
  • n = 0 flush left   

  • n = 1 centering 
    n = 2 flush right 
    n = 3 justified
     
    • ESC t n 
  • Select Character Table 
  • ESC t n is the command for selecting a character table to be used for printing where n is a variable. The following table lists the values for n and the character table associated with the value.   

  • 0 Italic 
    1 Graphic set/PC437 (US) 
    2 User-defined Characters (remap to 80h-FFh) 
    3 PC437 (US)
     
    • ESC ( t n1 n2 d1 d2 d3 
  • Assign Character Table 
  • ESC ( t n1 n2 d1 d2 d3 is the command for assigning character tables where n1,n2, d1, d2, and d3 are variables. Currently, variables n1, n2 and d3 MUST be n1=3, n2=0, and d3=0. Variable d1 is a number corresponding to one of the four tables selectable with the ESC t n command. This is the table that will be replaced. Valid values for d1 are 0, 1, 2, and 3 (see Table 1 below). Variable d2 is a number corresponding to a registered table. This is the table that will replace the table indicated by variable d1. Valid values for d2 are 0, 1, 3, 7, 8, and 9 (see Table 2 below).  
  •  
    • Table 1 (d1 Selectable Table)  

    • 0 Italic 
      1 PC437 (US) 
      2 User-defined Characters 
      3 PC437 (US)
  • Table 2 (d2 Registered Table) 

  • 0 Italic 
    1 PC437 (US) 
    3 PC850 (International) 
    7 PC860 (Portugal) 
    8 PC863 (Canada - French) 
    9 PC865 (Norway)
    • After using the ESC ( t command, the ESC t n command MUST be sent to select the table before printing from the new table. For example, the command ESC ( t 3 0 1 3 0 is sent (assign Registered Table 3 (PC850) to Selectable Table 1 (PC437). In order to print the character (ASCII 245), the command ESC t 1 must be sent.  

    • Some ESC/P2 documentation may illustrate as many as 22 different Registered Tables. The Registered Tables are a part of the character set, therefore, they are contained in the Character Generator ROM. The CG ROM differs based upon the destination country. For this reason, only the above Registered Tables are available on LQ-570, LQ-1070, LQ-870 and LQ-1170 printers sold for the U.S. market. Foreign Character Generator ROMs ARE NOT available in the United States. The following page contains a print sample of the Registered Tables available in printers sold in the U.S. In order to print the first 31 characters in Tables 1 through 9, the ESC ( ^ command must be sent. 

    • ESC R n 
  • select international character set 
  • n = 0 USA  

  • n = 1 France 
    n = 2 Germany 
    n = 3 United Kingdom 
    n = 4 Denmark I 
    n = 5 Sweden 
    n = 6 Italy 
    n = 7 Spain 
    n = 8 Japan 
    n = 9 Norway 
    n = 10 Denmark II 
    n = 11 Spain II 
    n = 12 Latin America 
    n = 13 Korea 
    n = 64 Legal
     
    • ESC % 
  • select character set 
  •  
  •  
    • ESC & NUL n1 n2 a1 data 
  • define user defined character 
  •  
  •  
    • ESC : 
  • Copy resident ROM character set to downloadable-character-set RAM. This allows you to be able to redefine a few characters and select the downloadable characters without having to define all 256 characters.  Must be done before redefining any characters.
  • ESC :  \000  n  \000
  • n=  0 = Roman font

  • >        1 = Sans Serif font
    >        2 = Courier
     
    • ESC 6 
  • sets characters 128 to 159 as printable characters,

  • expanding the printable character set.
     
    • ESC 7 
  • sets characters 128 to 159 to act as control characters identical to characters 0 to 31.
  •  
  •  
    • ESC ( ^ n1 n2 d1 . . . dk 
  • Print Data as Characters 
  • ESC ( ^ n1 n2 d1 . . . dk is the command for printing control codes as data where n1 and n2 are variables and d1 . . . dk represent the data that is to be printed as characters. The variables n1 and n2 tell the printer "the next xx ASCII codes are to be interpreted as characters instead of control codes". This command is used primarily to print displayable characters such as ASCII values 0 through 31 in Registered Tables 1 through 9 which are normally used as control codes (LF, FF, ESC, etc.)  

  • To determine the values for n1 and n2 perform the following steps. 
    1. Determine how many ASCII codes will be sent sequentially immediately following n1 and n2. 
    2. Using long division, divide the quantity of ASCII codes that will be sent sequentially immediately following n1 and n2 by 255. 
    3. The remainder in the quotient is the value for n1. 
    4. The whole number in the quotient is the value for n2. 

    EXAMPLE 
    1. The symbols for the different suits of a card deck (hearts, diamonds, clubs, and spades) are to be printed. These are each separate ASCII codes (ASCII codes 2, 3, 4, and 5 when using the PC437 Character table). 
    2. 4 divided by 255 = 0 with a remainder of 4. 
    3. n1 = 4 
    4. n2 = 0

     
    • BIT IMAGE  
     
    • ESC * m n1 n2 data 
  • select graphic mode 
  • 8-Pin Graphics:  

  • m = 0 = 60 DPI 
    m = 1 = 120 DPI 
    m = 2 = 120 DPI Hi Spd 
    m = 3 = 240 DPI 
    m = 4 = 80 DPI 
    m = 5 = 72 DPI 
    m = 6 = 90 DPI 
    m = 7 = 144 DPI 
    24-Pin Graphics: 
    m = 32 = 60 DPI 
    m = 33 = 120 DPI 
    m = 38 = 90 DPI 
    m = 39 = 180 DPI 
    m = 40 = 360 DPI
     
    • GRAPHICS 
     
    • ESC K n1 n2 data 
  • single-density 60DPI 
  •  
  •  
    • ESC L n1 n2 data 
  • double-density 120DPI 
  •  
  •  
    • ESC Y n1 n2 data 
  • hi-speed double 120 DPI 
  •  
  •  
    • ESC Z n1 n2 data 
  • quad density 240DPI 
  •  
  •  
    • ESC ^ 0 n1 n2 data 
  • 9-pin 60DPI 
  •  
  •  
    • ESC ^ 1 n1 n2 data 
  • 9-pin 120DPI 
  •  
  •  
    • ESC ? n 
  • reassign graphics mode 
  •  
  •  
    • ESC ( G 
  • tell me if you know 
  •  
  •  
    • ESC . 
  • tell me if you know 
  •  
  •  
    • ESC ( i 
  • tell me if you know 
  •  
  •  
    • ESC ( e 
  • tell me if you know 
  •  
  •  
    • ESC ( \ 
  • tell me if you know 
  •  
  •  
    • ESC ( s 
  • tell me if you know 
  •  
  •  
    • COLOR 
  • tell me if you know 
  •  
  •  
    • ESC r n 
  • color selection 
  • n = 0 Black  

  • n = 1 Red (Magenta) 
    n = 2 Blue (Cyan) 
    n = 3 Violet 
    n = 4 Yellow 
    n = 5 Orange 
    n = 6 Green
     
    • ESC ( r 
  • tell me if you know 
  •  
  •  
    • PRINTING MODE 
     
    • ESC ( K 
  • tell me if you know 
  •    

    My experience with sending printer command codes is with Paradox for DOS (a relational database). When designing a report, I create a calculated field and enter the Esc sequence within quotes. The quotes indicate that it's a string to be passed on, rather than a command for Paradox. "Esc" tells the printer that all characters before the next space are part of a printer command. It seems to be necessary to convert the "Esc" to ASCII but optional to convert the rest of the command. The "\027" is simply the ASCII equivalent of "Esc".
     

    I've picked some examples from a report;

    "\027x0\015" puts my ESC600 into compressed mode (17 char. per inch)

    "\027w\001" turns expanded mode on (large characters)

    "\027w\000" turns expanded mode off (back to 10 char per inch)


    blue = from the Paradox for DOS manual for LQ-1500 (dot matrix)

    navy = from the Epson's escp2.txt file

    fuchsia = from ESCODE.TXT, was pulled from the Epson bbs.

    purple = from Peter Curran's MX-100 (dot matrix) manual
     

    http://webpages.charter.net/dperr/links/esc_p2.htm


    Controlling a HP Printer Directly with PCL

    It seems that many people find it hard to configure DOS programs such as Sage, banking programs etc. to print in a sensible format to laser printers (or line / dot matrix ones for that matter).

    The following codes can be used in DOS batch files or within an application's configuration program for controlling a HP or compatible PCL printer:

     

    Characters ASCII codes Effect
    [ESC] ( s 3 B
    27 40 115 51 66 Bold On
    [ESC] ( s 0 B
    27 40 115 48 66 Bold Off
    [ESC] & d 1 D
    27 38 100 49 68 Single Underline On (use 3 for floating underline)
    [ESC] & d 2 D
    27 38 100 50 68 Double Underline On (use 4 for floating underline)
    [ESC] & d 0 D 
    or [ESC] & d @
    27 38 100 48 68
    27 38 100 64
    Underline Off (
    [ESC] & l 1O (el one Oh)
    27 38 108 49 79 Landspace
    [ESC] & l 0O (el zero Oh)
    27 38 108 48 79 Portrait
    [ESC] ( s 1 6 H
    27 40 115 49 54 72 16.66 cpi (132 columns in portrait, 160 landscape)
    [ESC] ( s 1 2 H
    27 40 115 49 50 72 12 cpi (96 columns in portrait, 136 landscape)
    [ESC] ( s 2 0 H
    27 40 115 50 48 72 20 cpi (160 columns in portrait, 220+ landscape)
    [ESC] & a [n] L
    [ESC] & a 0 L
    27 38 97 [n] [n].. 76
    27 38 97 48 76
    Left Margin [n] lines
    [ESC] & a [n] M
    [ESC] & a 1 3 2 M
    27 38 97 [n] [n].. 77
    27 38 97 49 51 50 77
    Right Margin [n] lines
    [ESC] & l [n] E
    [ESC] & l 1 E
    27 38 108 [n] [n].. 69
    27 38 108 49 69
    Top Margin [n] lines
    [ESC] & l [n] F
    [ESC] & l 6 6 F
    27 38 108 [n] [n].. 70
    27 38 108 54 54 70
    Bottom Margin [n] lines
    [ESC] 9
    27 57 Clear Margins
    [ESC] & l [n] C
    [ESC] & l 5 C
    27 38 108 [n] [n] 66
    27 38 108 53 66
    Line Spacing ([n]/48")
    [ESC] =
    27 61 Half line feed
    [ESC] & l [n] D
    [ESC] & l 9 D
    27 38 108 [n].. 67
    27 38 108 57 67
    [n] Lines per inch
    [ESC] & l [n] P
    [ESC] & l 6 6 P
    27 38 108 [n] [n].. 80
    27 38 108 54 54 80
    Page length [n] lines
    [ESC] E
    27 69 Reset printer

    In PCL each sequence of command typically starts with the Escape character, a start character, a value in text form, then ends in a capital letter.  You can combine more than one command which start with the same two characters after the Escape by changing the last letter of the first part to lower case and leaving off the next start letter, eg:

    [ESC] &l1O [ESC] &l1E [ESC]&l0L would become [ESC] &l1o1e0L

    It is often necessary to combine the commands like this as older programs typically only allow 10 or 12 characters to be entered for each effect.  To make an uppercase letter into lowercase add 32 to it's ASCII code.

    eg to Put a HP Laserjet 5Si into 132 column mode with 66 lines in landscape the following should work:

    [ESC] E [ESC] & l 1 o 0 e 6 6 f 9 D [ESC] & a 0 l 1 3 2 M [ESC] ( s 1 3 H

    Which is Reset, Landscape, 0 Top Margin, 66 Bottom Margin, 9 Lines per Inch, 0 Left Margin, 132 Right Margin, 13 Pitch Font.

    From a DOS batch file you can often send codes to a printer using ECHO commands which have been entered using EDIT.  This could be to a local printer or captured to a network printer, eg:

    ECHO ~E~&l1o0e66f9D~&a0l132M~(s13H > LPT1:

    where ~ is the [ESC] character which in edit can be entered with Control P then Control [ and shows as an arrow pointing to the left.

    Note in Windows 2000 and XP the & symbol is used to run two or more commands from the same command line therefore it is not possible to send a command exactly as above.  Workarounds include adding a double quote (") character prior to the escape string, e.g. ECHO "rest of the string" but this leaves the " character printed on the paper or adding the codes to a text file using EDIT then sending the text file to the printer with a line such as:

    COPY textfile.txt LPT1:
    or COPY textfile.txt \\server\share
    or TYPE textfile.txt > LPT1:
    or PRINT textfile.txt
    or NPRINT textfile.txt (for Novell systems)

    I have since found that you can use a circumflex character (^) to escape the ampersand (&) to make it show as text rather than be interpreted by Windows, e.g.

    ECHO ~E~^&l1o0e66f9D~^&a0l132M~(s13H > LPT1:

    From a simple DOS based BASIC such as Quick Basic 4.5 (QB45) you can send codes in a number of ways.  The easiest is to assign some codes to variables and use those in print # or lprint statements to the printer port.  You use the chr$() function to send unprintable codes such as Escape and Form Feed or those difficult to enter such as the double quote " which is chr$(34) i.e.:

    esc$=CHR$(27)
    boldon$=esc$+"(s3B"
    boldoff$=esc$+"(s0B"
    formfeed$=chr$(12)
    
    filenum=FREEFILE
    OPEN "lpt1:" FOR OUTPUT AS filenum
       PRINT #filenum, boldon$ + "This is in bold" + boldoff$
    CLOSE #filenum
    
    LPRINT boldon$ + "This is in bold" + boldoff$

    Changing Printer Display

    The following code sent to a HP Printer will change the message on the display to "Any message":

    [ESC]%-12345X@PJL JOB
    @PJL RDYMSG DISPLAY="Any message"
    @PJL EOJ
    [ESC]%-12345X

    [ESC] is ascii 27, Control [.  Enter in EDIT using Control P, Control [.

    Since looking for a good reference for some more exotic PCL codes I hadn't previously used I found this reference which you may find handy too: http://printers.necsam.com/public/printers/pclcodes/pcl5hp.htm

     

    Text links: Return ]