Printer Command Language

Note: This is an unofficial archive of a page which once existed at http://www.ajp.clara.net/hp.htm .


This page provides an unofficial guide to the basics of Hewlett-Packard Printer Command Language Level 3 with some extensions.  PCL-3 will work with the majority of HP Deskjet printers manufactured within the last few years as well as certain other printers.  If you are unsure whether PCL-3 will work with your printer, you can download a sample PCL file and copy it directly to your printer.  The DOS command to achieve this is: copy /b test.prn prn:   The Linux equivalent is typically: cp test.prn /dev/lp0

Hewlett-Packard can be found on the web at http://www.hp.com if you require details of the range of products and services they offer including those in the area of printing and imaging.  When compiling the following reference guide, I checked all commands using a HP Deskjet 320 printer which uses PCL-3 with extensions.  You may get slightly different results or more command options on your printer, particularly with commands relating to typefaces and page margins.


PC World

Dabs.com

John Lewis
You may also wish to browse the AJP Shop for more links to retailers based in the UK.

I found a very good PCL Wizard on Hewlett-Packard's site a while ago, which allowed you to create simple PCL strings quickly and easily.  It appears to have mysteriously disappeared, but please let me know if you find it elsewhere.  HP's site also provides a list of the main PCL commands for DeskJet series and LaserJet series users.  You may find this useful if you want to use a particular typeface, character set or paper size which I haven't listed in my guide.

A visitor of this site sent me a link to Developer's Guide to HP Printers which leaves my page rather redundant!  The same visitor also sent me some C source code for compressing PCL graphics data.  Thanks to Uwe for these.

Commands to enable colour printing are a useful extension of PCL.  I hope to add colour printing information soon, after further investigation.  In the meantime, you might want to consult some notes on colour printing for Pascal programmers instead.

Contents

The following topic areas are discussed on this page.  To jump to a specific topic, click on the link to that topic.  Alternatively, you can read the whole document in order.  The order in which I have chosen to describe the commands is not representative of the order in which they should be used, which will vary.  This is not necessarily a complete list of commands, but you should be able to achieve everything you want to using them.

Introduction
A brief introduction to the form PCL-3 commands take, and how to read my descriptions.
Page Setup
Paper size and orientation, print area and text wrapping settings.
Font Selection
Selection of character set, font, size, pitch and spacing.
Character Formatting
Setting of italic, boldface, underline, superscript and subscript.
Setting and Moving Print Position
Positioning and moving by row and column, dot position and decipoint.
Miscellaneous Commands
Printer reset and extended character printing.
Printing Raster Graphics
Setting resolution, compression and offset and printing graphics.

 
Introduction

Most of the characters which make up the PCL-3 commands are standard printable characters.  There are some exceptions, most notably escape character 27 (1Bh) which all PCL-3 commands begin with.  I will represent this character with the § character.  To eliminate any ambiguity caused by different character sets, I will show all commands as a series of hexadecimal values within square brackets as well as printable characters.

PCL commands follow a standard structure starting with the escape character.  After the escape character comes the command type, the command value and a terminator identifying the specific command.  An example of this is found in the font selection commands, all of which begin with §(s or [1B][28][73].  Commands of the same type can often be strung together without the need to include the command type bytes by changing the terminating character from upper to lower case.  For example, to choose a 12pt 10cpi font:
§(s12V§(s10H or [1B][28][73][31][32][56][1B][28][73][31][30][49]
can be replaced with §(s12v10H or [1B][28][73][31][32][76][31][30][49].

In a lot of cases, I have only listed one example of a command.  This is when it is clear what the command value represents.  An example of this is font size selection.  I have only listed §(s12V for 12pt, but clearly §(s6V is equally valid for 6pt.  Consult your manual or hunt around for a full list of valid typeface and size combinations for your printer.

[Back to Contents]
 
      
Page Setup
Select Page Orientation
§&l0O[1B][26][6C][30][4F]Selects portrait orientation
§&l1O[1B][26][6C][31][4F]Selects landscape orientation
Select Line Termination Method
§&k0G[1B][26][6B][30][47]Sets CR=CR LF=LF FF=FF
§&k1G[1B][26][6B][31][47]Sets CR=CR-LF LF=LF FF=FF
§&k2G[1B][26][6B][32][47]Sets CR=CR LF=CR-LF FF=CR-FF
§&k3G[1B][26][6B][33][47]Sets CR=CR-LF LF=CR-LF FF=CR-FF
Select EOL Wraparound
§&s0C[1B][26][73][30][43]Enables EOL wraparound
§&s1C[1B][26][73][31][43]Disables EOL wraparound
Select Paper Size
§&l0A[1B][26][6C][30][41]Selects default paper size
§&l1A[1B][26][6C][31][41]Selects executive paper size
§&l2A[1B][26][6C][32][41]Selects letter paper size
§&l3A[1B][26][6C][33][41]Selects legal paper size
§&l26A[1B][26][6C][32][36][41]Selects A4 paper size
Set Page Margins
§&a5L[1B][26][61][35][4C]Sets left margin to column 5
§&a70M[1B][26][61][37][30][4D] Sets right margin to column 70
§&l50P[1B][26][6C][35][30][50]Sets page length to 50 lines
§&l2E[1B][26][6C][32][45]Sets top margin to 2 lines
§&l42F[1B][26][6C][34][32][46]Sets text length to 42 lines
Select Perforation Skip
§&l0L[1B][26][6C][30][4C]Disables perforation skip
§&l1L[1B][26][6C][31][4C]Enables perforation skip
Select Print Quality
§(s1Q[1B][28][73][31][51]Selects draft quality
§(s2Q[1B][28][73][32][51]Selects letter quality
[Back to Contents]
 
   
Font Selection
Select Character Set
§(0U[1B][28][30][55]Selects ASCII character set
§(10U[1B][28][31][30][55]Selects PC-8bit character set
§(1E[1B][28][31][45]Selects ISO 4 UK character set
§(0I[1B][28][30][49]Selects ISO 15 Italian character set
§(2S[1B][28][32][53]Selects ISO 17 Spanish character set
§(1G[1B][28][31][47]Selects ISO 21 German character set
§(1F[1B][28][31][46]Selects ISO 69 French character set
Select Typeface
§(s3T[1B][28][73][33][54]Selects Courier font
§(s6T[1B][28][73][36][54]Selects Letter Gothic font
§(s4101T[1B][28][73][34][31][30][31][54]Selects CG Times font
§(s52T[1B][28][73][35][32][54]Selects Univers font
Select Font Pitch and Size
§(s10H[1B][28][73][31][30][48]Selects 10cpi pitch
§(s12V[1B][28][73][31][32][56]Selects 12pt size
Select Character and Line Spacing
§(s0P[1B][28][73][30][50]Selects monospacing
§(s1P[1B][28][73][31][50]Selects proportional spacing
§&l6D[1B][26][6C][36][44]Selects 6 lines per inch spacing
[Back to Contents]
 
  
Character Formatting
Select Italics and Boldface
§(s1S[1B][28][73][31][53]Begin Italics
§(s0S[1B][28][73][30][53]End Italics
§(s3B[1B][28][73][33][42]Begin Boldface
§(s0B[1B][28][73][30][42]End Boldface
Select Underline Styles
§&d1D[1B][26][64][31][44]Select single fixed underline
§&d2D[1B][26][64][32][44]Select double fixed underline
§&d3D[1B][26][64][33][44]Select single floating underline
§&d4D[1B][26][64][34][44]Select double floating underline
§&d@[1B][26][64][40]Turn off all underline
§&k0E[1B][26][6B][30][45]Cancel underline at EOL
§&k1E[1B][26][6B][31][45]Retain underline at EOL
Select Superscript and Subscript
§(s1U[1B][28][73][31][55]Begin superscript
§(s-1U[1B][28][73][2D][31][55]Begin subscript
§(s0U[1B][28][73][30][55]Resume normal print
[Back to Contents]
 
   
Moving Print Position
Positioning by Row and Column
§&a3R[1B][26][61][33][52]Move to row 3
§&a+2R[1B][26][61][2B][32][52]Move down 2 rows
§&a9C[1B][26][61][39][43]Move to column 9
§&a+4C[1B][26][61][2B][34][43]Move right 4 columns
§&a-6C[1B][26][61][2D][36][43]Move left 6 columns
Positioning by Dot
§*p80Y[1B][2A][70][38][30][59]Move to vertical dot position 80
§*p+20Y[1B][2A][70][2B][32][30][59]Move down by 20 dots
§*p64X[1B][2A][70][36][34][58]Move to horizontal dot position 64
§*p+8X[1B][2A][70][2B][38][58]Move right by 8 dots
§*p-6X[1B][2A][70][2D][34][58]Move left by 4 dots
Positioning by Decipoint (1/720")
§&a80V[1B][26][61][38][30][56]Move to vertical decipoint position 80
§&a+20V[1B][26][61][2B][32][30][56]Move down by 20 decipoints
§&a64H[1B][26][61][36][34][48]Move to horizontal decipoint position 64
§&a+8H[1B][26][61][2B][38][48]Move right by 8 decipoints
§&a-6H[1B][26][61][2D][34][48]Move left by 4 decipoints
Additional Positioning
Ctrl-H[08]Backspace
Ctrl-I[09]Tab
Ctrl-J[0A]Line feed (LF)
§=[1B][3D]Half line feed
Ctrl-L[0C]Form feed (FF)
Ctrl-M[0D]Carriage Return (CR)
[Back to Contents]
 
Miscellaneous Commands
§E[1B][45]Reset printer
§z[1B][7A]Perform self test
§Y[1B][59]Print control codes as characters
§Z[1B][5A]Use control codes (resume)
§&p3X[1B][26][70][33][58]Print next 3 bytes as characters
[Back to Contents]
 
     
Printing Raster Graphics
Select Graphics Resolution
§*t300R[1B][2A][74][33][30][30][52]Set resolution to 300dpi
§*t150R[1B][2A][74][31][35][30][52]Set resolution to 150dpi
§*t100R[1B][2A][74][31][30][30][52]Set resolution to 100dpi
§*t75R[1B][2A][74][37][35][52]Set resolution to 75dpi
Select Graphics Compression Mode
§*b0M[1B][2A][62][30][4D]Select mode 0
§*b1M[1B][2A][62][31][4D]Select mode 1
§*b2M[1B][2A][62][32][4D]Select mode 2
Start Printing Graphics
§*r0A[1B][2A][72][30][41]Start graphics at leftmost position
§*r1A[1B][2A][72][31][41]Start graphics at current position
Set Temporary Graphics Offset
§*b80X[1B][2A][62][38][30][58]Offset current line by 80 dots
Transfer Graphics Data
§*b4W[1B][2A][62][34][57]Transfer 4 bytes of graphics data
Finish Graphics
§*rB[1B][2A][52][42]Return to text mode

Typical Graphics Printing Procedure
To print raster graphics you must first set your graphics resolution.  The Deskjet 320 has a maximum resolution of 600x300dpi, but later models allow 600dpi in both dimensions.  Next you must set the graphics compression mode, which tells the printer in what form the graphical data will be sent.  When you have positioned the printhead where you want to start printing graphics, issue the Start Graphics command.  For every line of graphics you must have one new Transfer Graphics command, optionally preceded by a Horizontal Offset command.  The Horizontal Offset command specifies how far across the page to start the current line of graphics.  When you have finished transferring the graphics data, issue a Finish Graphics command.

Graphics Compression Modes
The HP Deskjet allows graphical data to be transferred in three formats.  All of these formats deal with dots which can either be black ink or paper left white.  These dots are dealt with in groups of eight, which occupy one byte of data.  The following paragraphs should explain each of these formats in detail sufficient for you to produce your own raster graphics.

Graphics Mode 0 (No Compression)
This mode transfers raw pixels in groups of eight.  Each arrangement of pixels is translated into one byte of information.  This is done by treating a group of eight pixels as binary 1s and 0s where black ink is represented by 1 and white paper by 0.  The lefthand pixel in the group of eight is the most significant bit, and the righthand one is the least significant bit.  To print [White][Black][Black][White][Black][Black][White][Black], convert to binary 01101101 = m or [6D].

Graphics Mode 1
In this mode, graphics data bytes occur in pairs.  The first byte of the pair represents the number of repetitions of the second byte, which is the data byte.  The data byte is in the same format as a data byte used in mode 0.  If you wanted to print 80 black pixels in mode 0, you would have to send ten bytes: [FF][FF][FF][FF][FF][FF][FF][FF][FF][FF].  The byte [FF] occurs 10 times, which is 9 repetitions, so you need only send: [09][FF].

Graphics Mode 2 (TIFF Group 4 Compression)
This mode is concerned with both repeating bytes and conventional non-repeating bytes.  The data bytes occur in groups of variable length.  The first byte of a group indicates whether a repeated byte or a series of unrepeated bytes follow.  If the first byte has a value from [00] to [7F] then it indicates a number of unrepeated bytes follow.  A value of [00] represents one unrepeated byte, and a value of [7F] represents 128 unrepeated bytes.  If the first byte has a value from [81] to [FF] then it indicates a repetition of the following byte.  A value of [FF] represents one repetition (two occurrences), and a value of [81] represents 128 repetitions.  If you wanted to print a pattern represented by the following thirteen data bytes in mode 0: [FF][FF][FF][FF][00][18][00][FF][FF][FF][FF] you could compress this data in mode 2 to just eight bytes: [FD][FF][02][00][18][00][FD][FF].

[Back to Contents]

Please link to http://www.ajp.clara.net rather than a sub page
Web page design by Andrew J Payne (ajp@clara.net) - March 2002