0

I have the following code which I print a label with the information of a product. But I have the problem that the product name is not centered. It happens to me that if the name is very long, it goes outside the limits of the label and does not appear. What I want is for the name to start from the center and expand along the label and if it exceeds the limits to continue writing on the next line.

I would appreciate any help

    ^XA
   ^CF0,30
  ^FO150,30^FDNombre del Producto^FS
  ^CF0,60
  ^FO200,90^FDPrecio^FS
 ^FX Third section with bar code.
  ^BY2,2,50
  ^FO170,180^BC^FD1234789^FS
 ^XZ
  • 1
    Use the `^FB` Field Block command. It defines the maximum width and height that text will be rendered, plus alignment. – Mark Warren Aug 25 '21 at 21:01
  • Does this answer your question? [ZPL How to center text with variable length](https://stackoverflow.com/questions/50483206/zpl-how-to-center-text-with-variable-length) – EdHayes3 Aug 26 '21 at 04:23
  • @MarkWarren I had left that part pending, until now the remote one. But I can't make it look good. How would the FB command work? Thank you very much in advance –  Oct 21 '21 at 20:14
  • @user11804298: What are the dimensions of the label and how much space do you want to allocate for the text to wrap? Can you post a picture of a label where the text has overrun and been clipped? – Mark Warren Oct 24 '21 at 22:44

1 Answers1

1

NOTE: This only works if you are using dots as the unit of measurements (this is the default but specified as ^MUd in the example below). If mm is used (^MUm) the center-thingy does NOT work properly (tested on labelary.com and Zebra S4m).


Use ^FB to define a Field Block. From the manual:

The ^FB command allows you to print text into a defined block type format. This command formats an ^FD or ^SN string into a block of text using the origin, font, and rotation specified for the text string. The ^FB command also contains an automatic word-wrap function.

You could view this example at labelary.com or tryit out yourself:

^XA
^MUd
^LH10,10
^CF0,50
^GB500,500,10^FS
^FO0,50  ^FDNormal^FS
^FO0,150 ^FB500,,,L ^FDLeft^FS
^FO0,250 ^FB500,,,C ^FDCenter^FS
^FO0,350 ^FB500,,,R ^FDRight^FS
^XZ

enter image description here

UlfR
  • 4,175
  • 29
  • 45