If you ever had to deal with PCL you would know that there is no command to centre the text. There are some printers that support HPGL command embedded in the PCL file, but not all. If we are printing a predefined text, we know the measurements and would set absolute positioning. But if we are dealing with data generated from a data source, then how can we centre the text? One way to do it is to know the width of every character in every font-family and when printing, calculate the width of the text in whatever unit we are using and then position the text accordingly. The other way is to write an email to your manager and tell them that unless they move to PostScript, there is no way you can centre the text correctly.

But if you really want to do it without having to dramatically change your code or moving away from PCL, there is a trick that you might or might not have figured it out or heard of it.

The trick is to print transparent text upside down in half the point size from the centre of the page. What you will print next will start exactly from where the last one ended. Now, change rotation back to normal, and print your text in intended size in black. This will work very well.

Choose transparent color [ESC]*vo1T
Rotate 180 degrees [ESC]&a180P
Drop the font size by half (assume your normal text size is 12) [ESC](s1p6v0s0b5T
Print your text
Choose black color [ESC]*v1oT
Change rotation back to normal [ESC]&a0P
Choose the normal font size [ESC](s1p12v0s0b5T
Print your text.

Note: Please refer to your printer manual for specific PCL commands, such as font sequence.


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *