question

kedargodkhindi avatar image
0 Votes"
kedargodkhindi asked TimonYang-MSFT answered

Help required on format conversion of labels

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.

dotnet-csharp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

TimonYang-MSFT avatar image
0 Votes"
TimonYang-MSFT answered

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.


2.png (19.6 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.