Help required on format conversion of labels

Kedar 21 Reputation points
2021-04-21T19:58:25.207+00:00

We integrate with various shipping vendors like UPS, Citilogistics to name a few. Based on the routing of the parcels processed in the facility, we call the shipping vendor APIs & get the labels in response in different formats.
Example - UPS provides the labels in ZPL, whereas another provides the label as PDF ( base 64 format).
We are currently automating the parcel processing for which we need to convert various formats like - PDF, Image, html to a common format "ZPL" for printing. .

PDF, Image are available in the base 64 format.

Example for various label formats -

  1. ZPL - Labelary Online ZPL Viewer
  2. PDF (in base 64 format) - attached PDF
  3. Html format.

We want to convert all the formats to common format - ZPL. Are there any libraries to convert pdf, image & html format to zpl.
Let me know if you have any ideas on the same, Thank you.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,604 questions
0 comments No comments
{count} votes

Accepted answer
  1. Timon Yang-MSFT 9,581 Reputation points
    2021-04-22T05:57:35.853+00:00

    I wrote a piece of code to convert pdf to ZPL, which requires 4 nuget packages:

    90178-2.png

    Code:

           static void Main(string[] args)  
            {  
                string filePath = @"";  
                  
                byte[] bytes = File.ReadAllBytes(filePath);  
                String file = Convert.ToBase64String(bytes);  
      
                int pageNum =  PageCount(bytes);  
      
                List<string> strs = new List<string>();  
                for (int i = 0; i < pageNum; i++)  
                {  
                    strs.Add(Conversion.ConvertPdfPage(file, dpi: 100, page: i));  
                }  
                  
                Console.WriteLine("Press any key to continue...");  
                Console.ReadLine();  
            }  
            public static int PageCount(byte[] pdf)  
            {  
                using (var stream = new MemoryStream(pdf))  
                {  
                    using (var reader = new PdfReader(stream))  
                    {  
                        using (var document = new PdfDocument(reader))  
                        {  
                            return document.GetNumberOfPages();  
                        }  
                    }  
                }  
            }  
    

    The package also provides a method to convert Bitmap to ZPL:

    Conversion.ConvertPdfPage(Bitmap bitmap)

    I have not found a way to convert html to ZPL, but there should be many ways to convert it to PDF or images.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful