Skip to main content

Well-formed PCL files

Creating PCL documents for predictable results

PCL documents are files of text and control codes designed to print formatted text and/or graphics on a laser printer made by HP or others. Formatting can set fonts, change character pitch, turn on underlining, etc. It can also specify job-level things, such as the size of the paper to use, orientation, etc. For purposes of this writeup, we're assuming these files are created by a program that is part of an application system. Also, we're talking about PCL-5; PCL-6 is entirely different.

The Problem

A particular PCL document may have been in use for many years, printing correctly on a laser printer. But when it is sent to a different laser printer (still a PCL compatible printer), it yields different results. Or, when it's send to our Print Wizard software to be converted to PDF, printed on a non-PCL printer, or used as an overlay, it comes out wrong. Very often, the problem is that the PCL document is not well-formed. Let me explain.

When a print job is send to a printer, there are many variables or settings that affect how it gets processed. One example is font size: how big should the letters be? If the print job doesn't specify this, by means of an escape sequence, it is open to question. In programming terminology, it's an uninitialized variable. In practice, it may be left over from a prior print job. If you reset the printer, by turning it off then on or sending it a reset sequence (<esc>E), many variables will be reset to factory defaults. Others, though will be reset to values that depend on how the front panel is configured. In the example of font size, the font size and the vertical line spacing will be reset according to the number of lines per page set in the front panel. So, if you send the job to a different printer, and it is set to a different number of lines per page, you'll get different results. If you send the job to Print Wizard, Print Wizard has some settings that can be configured by manually editing a profile file. But you don't want to do that.

The Solution

The solution to this set of problems is to include certain codes at the beginning of every print job to reset everything to your desired state. That is, initialize all variables. A print job with a proper and thorough initialization sequence is what I refer to as a well-formed PCL job.

I'll assume you know what an escape character is, if you've gotten this far. Also, I'll assume you know how to generate an escape character in your particular programming environment. I'll represent an escape character with <esc>.

In overview, you want to start with a reset sequence, then set everything that is still variable. I'll give examples which you can modify as needed. I won't cover all possible settings, just the ones likely to be an issue, based on my experience.

The Sequence

  1. Reset: <esc>E  This sets most but not all settings to a known status.
  2. Set paper size: <esc>&l2A  This selects letter-size paper.
  3. Page orientation: <esc>&l0O  This selects portrait mode.
  4. Top margin: <esc>&l0E  This sets the top margin to zero lines.
  5. Vertical Motion Index (VMI): <esc>&l8C  This sets the line advance, in 1/48-inch units. The 8 means 8/48, or 1/6 inch.
  6. Perforation skip: <esc>&l0L  Setting to 0 disables the bottom margin area.
  7. Reset cursor: <esc>&a0R  This sets the cursor at line 0, which is where the top margin is. Without this, page 1 will behave differently from page 2 and following.
  8. Symbol set: <esc>(0N  This sets high characters to be treated as ISO 8859-1 Latin 1.
  9. Spacing: <esc>(s0P  This sets fixed spacing (every character is the same width).
  10. Pitch: <esc>(s10H  This sets horizontal character spacing to 10 characters per inch. If you were setting up variable-pitch instead, you would set height here with <esc>(s12V for instance.
  11. Typeface: <esc>(s4099T  This sets Courier (scalable).

It is true that some of these sequences can be combined, using lowercase letters until the last one. See HP documentation for details.

This scheme assumes that the print data in the file forces a formfeed (advance to next page) by using a formfeed character (hex 0C). If, instead, the data simply linefeeds from one page to another, adjustments to the VMI and perforation skip may need to be made.

Finally, note that it's good practice to end every print job with a reset sequence, that is, <esc>E.

Copyright © 2024 Rasmussen Software, Inc. Legal Information & Privacy Policy
Send comments and suggestions to rsi@anzio.com