-1

My ZPL code:

^XA
^FO15,300^A0,25^FD Invoice #^FS
^FO150,300^A0,25^FD Date^FS
^FO300,300^A0,25^FD Cust #^FS
^FO400,300^A0,25^FD Name^FS
^FO650,300^A0,25^FD Amount^FS
^FO10,330^GB800,3,3^FS
^FO15,350^A0,25^TBN,305,25^FD200001^FS
^FO150,350^A0,25^FD10/26/2021^FS
^FO300,350^A0,25^FD100^FS
^FO400,350^A0,25^FDThis is a test customerrrrrrrrrr^FS
^FO650,350^A0,25^FD$129.90^FS
^XZ

The issue is that when a customer's name is too long it overlaps the the amount column. If the name is longer than the width of the column I would like for it to be truncated.

GSerg
  • 76,472
  • 17
  • 159
  • 346
owl1929839
  • 11
  • 2

2 Answers2

0

The only way I have found to clip text with ZPL is to draw a white box after the text where it may overrun. This is not a general purpose solution but it can be made to work for most cases. From your example:

^XA
^FO15,300^A0,25^FD Invoice #^FS
^FO150,300^A0,25^FD Date^FS
^FO300,300^A0,25^FD Cust #^FS
^FO400,300^A0,25^FD Name^FS
^FO650,300^A0,25^FD Amount^FS
^FO10,330^GB800,3,3^FS
^FO15,350^A0,25^TBN,305,25^FD200001^FS
^FO150,350^A0,25^FD10/26/2021^FS
^FO300,350^A0,25^FD100^FS
^FO400,350^A0,25^FDThis is a test customerrrrrrrrrr^FS
^FX Draw a white box where the text may over-run ^FS
^FO645,345^GB150,30,30,W^FS
^FO650,350^A0,25^FD$129.90^FS
^XZ
Mark Warren
  • 1,321
  • 1
  • 7
  • 4
  • Are you saying `^TB` does not work? – GSerg Oct 26 '21 at 21:13
  • @GSerg: Yes, `^TB` only clips on wrapped lines, after word wrapping. For example, if you used the example text `^FDThis is a test customerrrrrrrrrr^FS`, you will see it wrap after the `test` and clip the remaining text. – Mark Warren Oct 26 '21 at 21:21
0

I'll post this as an answer although @GSerg link in the comments should solve the issue. This is the relevant ZPL code:

^XA
^FO15,300^A0,25^FD Invoice #^FS
^FO150,300^A0,25^FD Date^FS
^FO300,300^A0,25^FD Cust #^FS
^FO400,300^A0,25^FD Name^FS
^FO650,300^A0,25^FD Amount^FS
^FO10,330^GB800,3,3^FS
^FO15,350^A0,25^TBN,305,25^FD200001^FS
^FO150,350^A0,25^FD10/26/2021^FS
^FO300,350^A0,25^FD100^FS

^FO400,350
^A0N,25,25
^TBN,220,100^FDVeryLongCustomerNameGoesHereAndWillBeTruncated^FS

^FO650,350^A0,25^FD$129.90^FS
^XZ

Note that the TB command only works for printers with firmware version V60.14.x, V50.14.x, or later, so if yours is older, this may indeed not work. This is the result in the simulator:

enter image description here

To wrap the text, simply set a smaller height for the text block as follows:

^FO400,350
^A0N,25,25
^TBN,220,30^FDVeryLongCustomerNameGoesHereAndWillBeTruncated^FS

Result:

enter image description here

As per comments, this will wrap if there is a space in the name. To always clip at the exact same location no matter the text, see @Mark Warren's answer. Another option is to do this in whatever code is creating the label ensuring the name is max N characters.

evilmandarine
  • 4,241
  • 4
  • 17
  • 40