Domanda

i'd like to know how to center barcode code 128. on the picture you should see that it is right now left justified. Label

my zpl:

^XA
^LH10,10
^FO0,0^XGE:SWESE001.GRF^FS
^FO440,0^XGE:SWESE000.GRF^FS
^FO0,70^FB550,50,0,C,0^AQN,25,30^FDSpraynozzle 50mm^FS
^FO0,130^BY2^BCN,30,Y,Y,N,N^FDS/N:941001-0114-0001^FS
^FO180,170^AQN,23,20^FDwww.swepro.com^FS
^XZ
È stato utile?

Soluzione

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 a 80 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 in mode C are stored in pairs. For more information on mode 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!

Altri suggerimenti

There is no ZPL command to center a code. Your program that generates the ZPL would need to auto calculate the position based on the size of the code and position using the coordinates.

Another solution to this problem, not as elegant as by Nicolas Garfinkiel, but much much simpler, is the following one.

Fundamentally the problem with Code 128 is that it is variable width. But is real life situation, we anyway use it as fixed width. This needs explanation. We position the code somewhere, and we expect it be no wider than some, otherwise it wouldn't fit, and we must reserve (keep empty) the space it is allowed to fill. Thus, even though it's variable width, we always need to allocate for it fixed area on a label.

So the solution to the centering problem would be to make Code 128 fixed-length.

If this is subset C (pairs of digits), then you need:

  1. Get any big enough number, of the form 100000..., so there are in total even number of digits.
  2. Add you code to it.

For example, if your code was 94100101140001, then you can add it with 10^16, and get this:

10000000000000000
   94100101140001
=================
10094100101140001

Thus the code becomes fixed-width, and can be hard-centered.

If your code is not subset C, and contains text, then (in pseudocode) you do:

my_code = "S/N:941001-0114-0001"
const_max_code_length = 24  (for example)
if my-code.length > const_max_code_length then error
padding_char = "="
result = ""
for (0..(const_max_code_length - my_code.length)) do
    result += padding_char
end_for
result += my_code

In case of your code, it will produce:

====S/N:941001-0114-0001

Then, no matter what text you put into it, it'll always be fixed length, and so will be positioned consistently.

I used it myself, before found this post. It's not OK, it's a hack, and what Nicolas Garfinkiel suggested is more right. The most appropriate solution would be, though, if ZPL itself would support code centering, and unfortunately it doesn't.

you must to tray to use :

 ^FO10,170^AQN,23,20^FDwww.swepro.com^FS

. where
. ^FOX,Y^AQN,...^FSX=x-axis location and Y=y-axis location

Click on the Checkbox "Print BarCode as a Graffic" in Barcode Proprieties.

It worked in my case.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top