If you’ve ever had to deal with PCL (Printer Command Language), you’ll know the pain: there’s no command to center text. Some printers support HPGL commands embedded in a PCL file, but not all. If you’re printing predefined text, you can work out measurements and use absolute positioning. Easy enough.
But when your text is dynamic — coming from a data source — things get tricky. How do you center that when you don’t know the width in advance?
Sure, you could:
- Measure the width of every character in every font
- Calculate the total text width on the fly
- Position accordingly
…but at that point, it might be easier to just email your manager and say, “Unless we move to PostScript or PDF, I’m out.”
But if you’re stuck in PCL land and can’t just rewrite your whole print pipeline, there’s a neat trick you might not have heard of (or maybe forgot).
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.
How it works
Because PCL tracks where each character ends when printing, this “ghost” print leaves the print cursor moved appropriately — even though nothing visible appears on the page. It’s basically a dry run.
Here’s how to do it:
Choose transparent color [ESC]*vo1T
Rotate 180 degrees [ESC]&a180P
Drop the font size by half [ESC](s1p6v0s0b5T ; (assume your normal text size is 12pt)
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.
Is this still useful today?
Is This Still Useful Today?
Depends.
✓ Yes, if:
- You’re maintaining legacy systems still spitting out raw PCL
- You’re stuck with dot matrix or industrial laser printers
- Your systems generate raw print streams rather than PDFs
✗ No, if:
- You’re using modern print engines (PDF, PostScript, GDI, etc.)
- Your printer auto-scales or centers text
- You have access to better layout tools
This trick still works in 2025. It’s a classic hack for a classic problem — and might just save your skin if you’re stuck with PCL and need decent-looking output without reinventing the print system.
0 Comments