Encoding Issues, help ZPL Code print headache

Greetings,

I Have a Zebra ZD220t and i do need to print some labels which have Arabic and English on the same label , i did tried all the possible options and it seems that somehow XOJO is messing up the Arabic part.

I imported the source csv but using a plugin on another project , i use Chilkat to load the csv and on the file encoding , because it comes from a windows machine i put csv.LoadFile2(FileName, "windows-1256" ) which made the text to show properly.

Now, on my side i try testing one test code found on the internet which is

#If TargetWindows Then
  
  Dim printer As New directPrint
  Dim job As Integer
  
  If printer.Open("barcode") Then
    job= printer.StartDoc("BClabel")
    
    If job > 0 Then
      
      If printer.StartPage Then
        
        Call printer.Write("^XA")
        
        Call printer.Write("^PW464") ' 58 mm * 8 dots per mm = 464 dots
        Call printer.Write("^LL312") ' 39 mm * 8 dots per mm = 312 dots
        
        Call printer.Write("^CI28")
        Call printer.Write("^CWZ,E:TT0003M_.TTF")
        Call printer.Write("^FT60,100^PA0,1,1,1^AZN,30^FDBonjour en Arabe : صباح الخي^FS")
        
        Call printer.Write("^XZ")
        
        printer.EndPage
      End If
      printer.EndDoc
    End If
    
    printer.Close
  End If
#EndIf


But when printing it comes like this :

Which makes me think that there is some fishy with the encoding of the text and the way it is handled.

I looked on xojo Encodings part and i did not found any

windows-1256 encoding

So can someone help me here and tell me what encoding i should use in order to show properly.

Thanks

What’s the actual issue with the print?

In the meantime i did play with the Zebra Designer and tried to export the ZLP code for it and it seems that if i paste this in the Call printer.Write, i get it printed properly but it seems that it converts the arabic into graphics then saves it and encodes it in a Z64 format then it prints

^DFE:Test.ZPL^FS
~TA000
~JSN
^LT0
^MNW
^MTD
^PON
^PMN
^LH0,0
^JMA
^PR4,4
~SD29
^JUS
^LRN
^CI27
^PA0,1,1,0
^MMT
^PW464
^LL312
^LS0
^FT6,48^A0N,28,38^FB458,1,7,C^FH\^CI28^FDTEST\5C&^FS^CI27
^FT15,290^A0N,28,20^FH\^CI28^FDPrice : 100 QR^FS^CI27

^FT15,242^A@N,20,20,TT0003M_^FH\^CI28^FDTunic Passioni Turquoise 15136^FS^CI27
^FO219,169^GFA,541,736,32,:Z64:eJyVks9Kw0AQxmeywhaEVilIEW3iE+ixBzEpCnrwIdan8JgJCvUgtUdPPomHCQp6EJ8hIuJRwUvB0nVmI/4DETeB3W9+m9nJfAvwfcz90ND4ss7eucUp8jo81xzl0TfwXiTLwL2ZSCjqgIVZAmQRFWDP0Cy1zNSwHyg3pxDDsswkwgF2rKjUUKt8HHT1qA6shxpqHs2hqNxQXF4MmxLCJVj7qM+BGem8b8bLbIYhdmx60NfvHYHL2qM+lLBtJvNsm6H+Y3sOfUnOz4zOrRztFXdkrdTfbWl9cGPPYC/wy7Zzq42anyDH73xmAJIastFW2yVJIykSstIBNidaP+zOFJRQInx33iVrnxxvm4FbTyllnr33eZV6X/hvfCfwQvir8Ljm1mJZ1vzaeMrpwHP+8pQqJ+VDLO+v9HzJQ1DhQfXZJgfWqD91/8noHnb6Exg8ZOET9W8sclBY2GT0VfLAamJU9YXDGHkDtX85TCEl8Bzfkppos5S+Xp+u2NfSbfYwmBip+v9Y+IMv/gbeADW6nEY=:A758
^BY3,3,62^FT63,126^BCN,,Y,N,,A
^FN1"BC"^FS"

I have no idea about Arabic but looking at the writing , this is what i Input “صباح الخي” and look at the label what it prints. From what i got that is wrong , so i assume that is an encoding issue.

Might be. You are also changing script directions in the middle of a line of text, which may throw the printer for a loop. Given the fact that the text is correct except for the first character or two, I tend to think that your encoding is correct and there’s a glitch in the printer.

Try printing your Arabic text without the Latin text and see what happens.

Well, printing same thing with the Zebra designer app, it works properly and whatever i input there it prints same thing so i doubt that the printer has issues and from what i read ^PA allows bidirectional text which should allow it to handle it properly .

And all is described here Zebra Support Community

Strings in Xojo are UTF8 by default. If you place your test into a string variable and then use convert encoding to swap it to the correct encoding you may solve the problem. In terms of encodings “Windows-1256” is called “WindowsArabic” by Xojo.

var ArabicStringUTF8 as String = "Bonjour en Arabe : صباح الخي"
var ArabicStringWin as String
ArabicStringWin = ArabicStringUTF8.ConvertEncoding( Encodings.WindowsArabic )

#If TargetWindows Then
  
  Dim printer As New directPrint
  Dim job As Integer
  
  If printer.Open("barcode") Then
    job= printer.StartDoc("BClabel")
    
    If job > 0 Then
      
      If printer.StartPage Then
        
        Call printer.Write("^XA")
        
        Call printer.Write("^PW464") ' 58 mm * 8 dots per mm = 464 dots
        Call printer.Write("^LL312") ' 39 mm * 8 dots per mm = 312 dots
        
        Call printer.Write("^CI28")
        Call printer.Write("^CWZ,E:TT0003M_.TTF")
        Call printer.Write("^FT60,100^PA0,1,1,1^AZN,30^FD" + ArabicStringWin + "^FS")
        
        Call printer.Write("^XZ")
        
        printer.EndPage
      End If
      printer.EndDoc
    End If
    
    printer.Close
  End If
#EndIf

See if that works.

Could actually be ArabicStringUTF8.ConvertEncoding( Encodings.WindowsArabic ) ?

1 Like

and unfortunately same issue, even if doing that , no change at all

Is it possible that “directPrint” converts everything to UTF8? Try using standard Xojo printer commands to send your instructions? Although that looks too high level, especially for a label printer.

apparently no, i took the code from here from the forum and adapt it to work on the latest xojo , and it uses RAW to send the data to winspool.drv
I don’t see any encoding parameters

If you look at the two strings ArabicStringUTF8 and ArabicStringWin in the debugger is the binary format any different?

It is worth adding this line, just before the convert encoding, to guarantee is it correctly tagged as UTF8.

ArabicStringUTF8 = ArabicStringUTF8.DefineEncoding( Encodings.UTF8 )

Apparently they are not same

Screenshot 2024-06-01 at 22.34.57

Screenshot 2024-06-01 at 22.34.42

Considering that the encoding changed , is that normal ?

Yes, very. It proves that the ConvertEncoding is actually doing the job. It is possible that the Zebra requires z64 encoding to cope with non-ascii input. Trouble with z64 is it required LZ77, which I’m not aware of an option for Xojo. You could just try Base64, which is the other half of the equation.

Call printer.Write("^FT60,100^PA0,1,1,1^AZN,30^FD:B64:" + EncodeBase64( ArabicStringWin ) + ":^FS")     

There may be more to it than that. I’ve looking at the z64 example you provided.

OK, it needs a checksum on the end It should go:

Call printer.Write("^FT60,100^PA0,1,1,1^AZN,30^FD:B64:" + EncodeBase64( ArabicStringWin ) + ":" + Hex( CheckSum ) + "^FS")     

Where CheckSum is a CRC checksum of the data in EncodeBase64( ArabicStringWin ).

Well, unfortunately does not work, your code is just printing the Base64 converted string and that’s about it, in order to print graphics you need more than that but i tested all the options and no luck

To my uneducated eye, the Arabic part seems fine for the second word, but wrong for the first one. If encoding is the same for all the Arabic part, how can only the first word be wrong ?

If it is encoded just using EncodeBase64 then you need to use B64 tag rather than Z64.

According to the Zebra manual:

I thought your example was what had worked using the Zebra printer software.