How to convert base64 string to zpl2 in C# .NET

// Expert user has replied.
l lakshika siyanayake 3 years 7 months ago
1273 3 0

I'm a C# .NET developer who sends the DHL shipment request to DHL XML-API web service and get the response to print labels, The DHL web services sends the Label (ZPL2) in Base64 encoded string. How to decode this and send this label to a Zebra printer? I couldn't find any references anywhere on how to do this task.
I need to do this in C# .NET

Please Register or Login to post a reply

3 Replies

J Jimmy Smith

Hi Iakshika,
Is there any chance you can share some example code for sending the string to zpl2? I have a similar issue and am currently converting the base64 to an image and printing that. But I think it would be cleaner to convert the base64 to zpl2.

Y Yanis Dalabiras

Hi Iakshika,
It looks like you need to add the ZPL header to your Base64  image string to tell the printer to store your image so you can print it.  Below is a string that, if you put in in just before your image string, might work.  I say might because I think it may need a CRC for the encoded data as well.  More info on this command can be found in the ZPL Programming Guide, page 169.
~DGE:FILENAME,8173,,B64:XlhBCl5...

It's probably easier to us the Graphics Converter tools that zebra has to offer.  These tools can take graphics in a number of different image formats and provide the full image format that is downloadable to Zebra printers.   Zebra Setup Utilities and ZebraNet Bridge both have tools to do this.  You can store the logo in flash memory on the printer and never have to send the logo again.

P Pietro Francesco Maggi

You can use the method: Convert.FromBase64:
Convert.FromBase64String Method (String) (System)

Implementing something like:
public static string Base64Decode(string base64EncodedData) {  var base64EncodedBytes = System.Convert.FromBase64String(base64EncodedData);  return System.Text.Encoding.UTF8.GetString(base64EncodedBytes);}

~Pietro

CONTACT
Can’t find what you’re looking for?