barcodezebra-printerszpl

How to calculate the width (in dots) of this zpl barcode?


^XA
^FO0,90^AD^BY3
^BCN,100,Y,N,Y,A
^MD10
^FD1458622235534^FS
^XZ

Using Label Viewer I was able to play around with ZPL and after reading some documentation figured out that ^FO0,90 is what positions the barcode. 0 is for the number of dots from the left and 90 is for the number of dots from the top.

My question is, how can the width of the above bar code be calcuated in dots? If I know the width of the barcode, I can then center it programmatically.

The printer's resolution is 203dpi and given a 3' (width) x 2' (length) tag, that is 610 dots across.

What is the formula to calculate the width of a ZPL Barcode?


Solution

  • I suggest you have a look at the Code 128 wikipedia article for the details.

    The natural unit of length for code 128 is the narrow bar width noted x (in your ZPL code set to 3 dots). A code 128 barcode (excluding the two 10x quiet zones) is made up of

    1. a start character (11x wide)
    2. n encoded character of width 11x
    3. a CRC (11x wide)
    4. a stop character (12x wide)

    If your data takes n encoded characters, the length of the barcode is (34 + n*11)x. In your case, x is 3 dots, so at 8dot/mm the barcode will be (12.75 + n*4.125)mm wide.

    You have to look into the encoding to figure out n. Minimal encodings are not unique, but in your case the data will be encoded with 8 barcode characters: 6 code C character (for 6 pairs of digits), 1 switch code character and 1 code A character (for the last digit). The barcode should be 45.75mm / 366dot wide.

    There is a little issue with your ZPL. You specified a UCC checkcode on a non UCC barcode. I am not familiar with UCC/GS1-128 barcodes but that might introduce extra barcode characters or be irrelevant.

    Also you might consider padding your timestamp with a leading 0. With Code 128, pairs of digit have a better encoding. A 14-digit barcode will be be 4.125mm shorter.

    I just mentionned the quiet zone, barcode readers require them.