How to print a tilde (~) in Zebra Programming Language (ZPL)
Asked Answered
I

2

8

I am maintaining a program that outputs ZPL to a label printer. Today, the character sequence ~Ja came in as part of a string to be printed, which is ZPL's "cancel all" command. Needless to say, the label did not print.

Is there an easy way in ZPL to escape a tilde?

Intermarriage answered 29/5, 2013 at 18:47 Comment(0)
R
14

You can use ~CT or ^CT to change the tilde control character to any other ASCII character, and then you can print tildes normally. However, the new control character won't be printable. This is probably going to be quite a hassle to maintain.

An example changing the control command prefix to +, taken from page 165 of the ZPL II programming guide:

^XA
^CT+
^XZ
+HS

If your string is represented as field data with ^FD, ^FV, or ^SN, you can use ^FH to encode the tilde in the string with its hex value, 7E.

An example, taken from page 192 of the ZPL II programming guide:

^XA
^FO100,100
^AD^FH
^FDTilde _7e used for HEX^FS
^XZ

Output:

Tilde ~ used for HEX

Roscoe answered 29/5, 2013 at 19:15 Comment(1)
PDF link is broken.Apteral
C
2

~ can be printed by replacing to \7E

It seeems like replacing these three characters will allow any key on the keyboard to print fine. I figured this out using ZebraDesigner, printing to a file and seeing what characters they escape.

\ to \1F - do this first or it will break the two below

~ to \7E

^ to \5E

Here is the code in C#

private static string escapeChars(string working)
{
working = working.Replace(@"\", @"\1F");
working = working.Replace(@"~", @"\7E");
working = working.Replace(@"^", @"\5E");
return working;
}
Cape answered 20/12, 2021 at 20:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.