Trying to print a code 128 barcode with corresponding text.
^XA
^FO30,40
^BCN,50,Y,N,N
^FDGA1234567890^FS
^XZ
However if I try to make the font of text bold, it aligns to the left. How can I keep the text center aligned?
^XA
^FO30,40
^A0B,30,30
^BCN,50,Y,N,N
^FDGA1234567890^FS
^XZ
You can try using the Field block (^FB). It wraps your text and you can apply justification rules on it. To use it you need to set the "print interpretation line" setting of ^BC to "N" (false) and insert the desired text separately. The downside is that while you can justify the text to center, you can not center the barcode. And that might be a problem, because the Code-128 changes its size depending on its content. So, this "solution" kind of "works", but in a way, that YES it is misaligned, BUT at least it is less misaligned than before. If you give it time, you can make it work better and look quite nice and sort of aligned. Or if you use another programming language to generate the ZPL, you can calculate the Field origin (^FO) of the barcode depending on its content and make it almost perfectly aligned.
Code example:
^XA
^FO30,40
^A0N,30,30
^BCN,50,N,N,N
^FDGA1234567890^FS
^FO0,100
^A0N,30,30
^FB400,1,0,C
^FDGA1234567890\&^FS
^XZ
Result:
But as I stated before, this is aligned just for this data. When you change the data, it might get misaligned. If you use longer data string, it will get misaligned for sure.
I hope I helped you.