I'm posting my solution in case someone is looking for it. As E_S mentions, in order to center a barcode in a label you have to calculate it by code following these steps:
- Check your narrow bar width, in your case 2
(^BY2)
- Find out your label total width in dots. For this you have to know what is your printer's resolution
(eg: 8 dots / mm)
. so if you have a80 mm
wide label,80 * 8 = 640 dots
- Count each character in your barcode, including invocation codes and check digit as specified below. For information on invocation codes see: https://www.zebra.com/content/dam/zebra/manuals/en-us/software/zpl-zbi2-pm-en.pdf (Page 95)
- Note that invocation codes
(">:", ">5", etc.)
count as one character, and that characters inmode C
are stored in pairs. For more information onmode C
, refer to http://en.wikipedia.org/wiki/Code_128 - If your barcode is
>:S/N:941001-0114-0001
you have to count [start code B] + [20 characters] + [check digit] = 22 - If your barcode is
>:S/N:>5941001>6->50114>6->50001
you have to count[start code B] + [4 characters for 'S/N:'] + [mode C invocation] + [3 characters for '941001'] + [mode B invocation] + [1 characters for '-'] + [mode C invocation] + [2 characters for '0114'] + [mode B invocation] + [1 characters for '-'] + [mode C invocation] + [2 characters for '0001'] + [check digit] = 20
- Every character occupies 11 units mixing spaces and bars, with the exception of
stop code
that has 2 extra units (that is a total of 13) - Here comes the good stuff... The barcode width is:
((chars counted [22 or 20] * 11) + (stop char * 13)) * narrow bar width = 510 dots or 466 dots
- Now all we have to do is
round((label width - barcode width) / 2)
and use that to position the barcode with^FT
That's it! Hope it helps someone!