PCL – Centring Variable-width Text

Published by Hameed on

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 regular size in black. This will work very well.

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

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


Hameed

Yet another software developer with interest in OO, Open Source, Social Media, politics, Islam and ...

0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: