New line in Zebra ZPL
Asked Answered
A

8

20
  1. How do I put new line characters for my "Text"? Say for example:

    Hello World
    

    will become

    Hello
    World
    

    Is there anyway that I can put a new line character for my code like this?

    ^FT78,76^A0N,28,28^FH\^FDHello\nWorld^FS
    
  2. If the "text" in my label is too long, how would I put another line to it?

Acknowledge answered 16/11, 2012 at 12:7 Comment(0)
A
17

I suggest you combine the answers from Thorsten and Dharmesh for maximum effect:

^FB400,2,0,C^FO0,50
^FDHello\&World^FS

Doing so will yield a label that looks like this:

result saying "Hello World"

The nice things about this approach are two: First, the text block will position and align the new line appropriately. And second, you have complete control over where the line break actually takes place.

Appulse answered 17/12, 2014 at 12:54 Comment(1)
For anyone trying out this answer but not getting the desired result: I tried this and it didn't work, until I removed the ^FH\ preceding my ^FD. Then everything worked as expected.Mollee
C
16

Use \& for new line

^FT78,76^A0N,28,28^FH\^FDHello\&World^FS
Champion answered 10/7, 2013 at 16:30 Comment(0)
W
8

I know this question is pretty old, but I found out that the ^FB command (Field Block) is actually pretty good at wrapping text:

I used a line like this:

^A0R,54,54^FO505,3424^FB630,2,0,L,0^FDThis is a pretty long line of text^FS

and it got wrapped into two lines nicely. The only thing you need to mind is that wrapping seems to take place at spaces only, not at commas or any other punctuation marks.

Worktable answered 4/2, 2014 at 10:57 Comment(1)
Utilizing the FB command is the best way to handle multiple lines.Strafford
U
5

The ^FX doens't understand \n, you will need to pass it \0A (the hex equivalent of \n) ASCII wiki page

So your ZPL should look like

^FT78,76^A0N,28,28^FH_^FDHello_0AWorld^FS

I changed the hex char to be _ vs \ so as others that look at this when you are done don't get confused.

Jason's idea about using the ^FB command is an excellent idea. It has some odd properties to it (with text rotation), but in general is a for text wrap.

Unsought answered 3/2, 2013 at 16:51 Comment(0)
N
4

While this question is a little older, it does serve to mention that the ZPL command ^FT is the command that dictates where the text element appears. The 78 and 76 correspond to the label's X-axis and Y-axis, respectively, and the unit of measure is dots. With this in mind, the previous answer is correct in principle. You can call another ^FT command with the y parameter being changed, such as this:

^FT78,78^A0N,28,28^FH\Hello^FS
^FT78,110^A0N,28,28^FH\World^FS

As an alternative, the ZPL manual details the ^TB (textbox) command, which includes automatic word wrapping.

Norine answered 19/12, 2012 at 5:0 Comment(0)
T
3

Doesn't answer the original question but for anyone using ZPL for unicode this may be of help.

I am using ^TB for Arabic text and found \& didn't work to create a new line.

What did work was to convert new line to hex (_0A) and use that.

For example:

^XA
^LL0406
^CI28
^CWZ,E:TT0003M_.FNT
^PA0,1,1,0

^FO609,50,2
^AZN,40,35
^TBN,559,300
^FH
^FD
_D8_B4_D8_B4_D8_B4_0A <-- new line
_D8_B4_D8_B4_D8_B4_0A <-- new line
_D8_B4_D8_B4_D8_B4
^FS


^PQ1
^XZ

... would output a ticket like this:

ششش
ششش
ششش
Thad answered 3/4, 2017 at 10:59 Comment(0)
C
-5

Unfortunately, You can't really do that. You have probably found that text which is too long it wraps around back onto the same line. You have to create a new line to accommodate the text. I forget which of the numbers in that string are the positions (probably the 28,28) try adding a line, changing those to 34,28 and see if it moves to a new line below.... Just play with those 4 numbers at the front of that line. One is a font size (which might help you) and 2 of the others are position from top and right. an easy way to play with those is just to edit the file with a text editor and do a copy command from the command line to the printer UNC path and see what you get. (i.e. copy "C:\test.txt \127.0.0.1\zebra). Hope this helps.

Calcimine answered 17/11, 2012 at 22:49 Comment(0)
L
-5

For android, "\r\n" works for adding a line break.

text.replaceAll("\n", "\r\n");
Liverpudlian answered 9/10, 2021 at 11:49 Comment(1)
How is this related to Zebra printers and the ZPL programming language?Putrescible

© 2022 - 2024 — McMap. All rights reserved.