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
Rotate 180 degrees
Drop the font size by half (assume your normal text size is 12)
Print your text
Choose black color
Change rotation back to normal
Choose the normal font size
Print your text.
Note: Please refer to your printer manual for specific PCL commands, such as font sequence.