Carnation Software
MacWise - Macintosh Terminal Emulation - telnet / serial for OS X - Wyse, Viewpoint, VT100, VT220

Controlling a Printer Directly with PCL Commands

Here are some of the more common codes that can be programmed on the host as a print job sent to MacWise for controlling a HP or compatible PCL printer:
See "Printing directly to a printer using PCL commands with MacWise"

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 Landscape
[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 [.


PCL Technical Reference Manual.

Printing_Direct_With_PCL_MacWise.html