|Free AS400 Downloads
|Free Testing Downloads
AS400 PCL Printing
This is one man's explanation of how to implement advanced printer functionality on your AS400 without the need to buy AFP or special printers. You can use just a basic printer - I've used a HP deskjet - running as
a SCS printer under TCP/IP to perform the actions below. This article assumes that you know how to set up such a printer, and have already done so.
What is this PCL printing then ?
PCL is the printing language used by HP printers, and many others. When you print to your laserjet or deskjet from windows, the text, images, fonts etc are converted by the printer driver into a language format that the printer can understand. Even when printing from your AS400 via a remotely attached TCP/IP writer, the AS400 itself via the device type does the conversion for you.
so why do you need to learn it ? Well, the AS400 without AFP on a SCS printer implements only a standard set of instructions. Things like mixing fonts on a page, drawing boxes, etc are just not implemented. So, we can send PCL commands direct to the printer, without translation by the AS400, to achieve some of these goals.
How do I send codes to a PCL printer from my AS400 ?
IBM conveniently provide a mechanism to send data directly to a printer via DDS, using the keyword TRNSPY. This sends a byte string without alteration through to the printer. You can "conveniently" send this in the form of a hex string, an example of this is below:
We've also learned out first PCL command, "Reset all". PCL defines this command as being made up of the escape key followed by a capital E. Looking these codes up in our ASCII table reference we see that the escape key is 1Bh and the letter capital E is 45h. So, by use of the TRNSPY keyword, we send these bytes of to the printer.
Obviously "Reset all" is just an instruction to prepare the printer for what we really want. So let's try a more interesting example, setting the margin.
This is more interesting in that we also get to send the printer a numeric value of our choice - a "variable" so to speak, although in our code this
will be hard coded. Let's set a top margin of 1, meaning 1/10 of an inch. The format for sending a "set top margin" command is as follows:
So what other codes are there ?
In short, loads, of which I have only used a few, as my needs were few. For my project I needed to specify a proportional font, some margins, some column positioning (to correspond with the pre-printed form I was using and that's about it really. So, following now is the full code I used for the record format that initialised the printer.
Having setup the page defaults, I then used the column positioning PCL commands to get my text in exactly the right place on the page. The command is <ESC>*p, followed by the number of units across, followed by a capital X. For my needs I needed 100 units, so the DDS looked like this. Note the use of the PCL before the normal DDS, and also the use of "+ 1" for the field position.
It's also a good idea to finish the printing with another reset command, ie <ESC>E. I set up a separate record format for this in the DDS
PCL Reference material
HP have produced some very useful PCL reference material in the form of a 2-part PDF guide. You can download the guide in two parts from hp. Here is the HP PCL5 Programmer's guide pt1, and here is part two.