5 Replies Latest reply on Jun 20, 2016 8:34 AM by Robin West

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

    lakshika siyanayake

      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

        • Re: How to convert base64 string to zpl2 in C# .NET
          Pietro 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

          1 of 1 people found this helpful
            • Re: How to convert base64 string to zpl2 in C# .NET
              lakshika siyanayake

              Hi Pietro,

              Thanks for your answer. Now labels are generating successfully. We are doing this for DHL. when we are save the labels as a PDF DHL logo has displayed, but when we directly send  byte array to the zebra printer, logo has not printed on the label. Is there any reason for that? how do we fix that issue?

                • Re: How to convert base64 string to zpl2 in C# .NET
                  Pietro Maggi

                  Hi Iakshika,

                  can you post/attach here a sample ZPL2 label you're getting back from DHL XML-API web service?

                   

                  And which printer/fw release are you using?

                   

                  With this information we (especially rwest@zebra.com and her team :-D ) can provide some help.

                   

                  Ciao

                  ~Pietro

                    • Re: How to convert base64 string to zpl2 in C# .NET
                      lakshika siyanayake

                      Hi Pietro,

                       

                      Thanks for the quick response. Here I have attached the label output that we got from the printer. We use  ZebraS4M printer. Following is the corresponding base64 encoded string that we are got from DHL XML-API web service response.

                       

                      XlhBCl5GVDIyLDQzCl5BME4sLDM2Cl5GREVYUFJFU1MgV09STERXSURFXkZTCl5GVDIyLDQzCl5BME4sLDM2Cl5GREVYUFJFU1MgV09STERXSURFXkZTCl5GVDY5LDcwCl5BME4sLDE1Cl5GRDIwMTYtMDYtMTcgWE1MUEkgNS4yIC8gKjkwLTE2MDQqXkZTCl5GVDM4OSw1OAp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lzdHJhdGlvbiByZWd1bGF0aW9ucy4gRGl2ZXJzaW9uIGNvbnRyYXJ5XkZTCl5GVDEyLDg0NwpeQTBOLCwyMQpeRkR0byBVLlMgbGF3IHByb2hpYml0ZWQuXkZTCl5GTzAsODU3Cl5HQjc4MCwwLDIsQl5GUwpeRk81MSw5MDIKXkJZMywyLjcsMjA1Cl5CM04sTiwyMDUsTixOCl5GRDM4NzkxOTY0MTReRlMKXkZUMTY5LDExMjgKXkEwTiwsMjYKXkZEV0FZQklMTCAzOCA3OTE5IDY0MTReRlMKXkZUNjQyLDkwNgpeQTBOLCwyMApeRkRDb250ZW50cyA6XkZTCl5GVDY0Miw5MjcKXkEwTiwsMTgKXkZEU2hpcG1lbnQgRGVzY3JpXkZTCl5GVDY0Miw5NDgKXkEwTiwsMjAKXkZEcHRpb24gSGVyZV5GUwpeRk8wLDExNDkKXkdCNzgwLDAsMixCXkZTCl5GVDgsMTE2NwpeQTBOLCwyMQpeRkRMaWNlbnNlIFBsYXRlcyBvZiBwaWVjZXMgaW4gc2hpcG1lbnReRlMKXkZUOCwxMTg4Cl5BME4sLDIwCl5GREpEMDEzMDM2NTM4MTY1MjQ4Nzc4XkZTCl5GVDM1NCwxNTI4Cl5BME4sLDIwCl5GRC0gcGFnZSAxIG9mIDEgLV5GUwpeWFoKLabel01.jpgLabel02.jpg

                • Re: How to convert base64 string to zpl2 in C# .NET
                  Robin West

                  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.