1

I want to show the UPS Label size in the following size Width = 4 inches and Height = 8 Inches

But UPS API returns the GraphicImage in base64 format when I display it on my browser Like

it display the very large size image on my browser Like width:1400px and Height:800px;

when I print this image on my ZP450 printer it printed very small image on page even that is not readable on page.

any help is much appreciated, how I display the small level image on browser

or send the print directly using base64 code But I want to print image size large when it printed on page Like UPS.COM printed.

Tomasz Kowalczyk
  • 10,472
  • 6
  • 52
  • 68
user3543056
  • 11
  • 1
  • 3

2 Answers2

3

Before sending a UPS GraphicImage label using ZPL format to a Zebra Printer, you need to convert it from base64 string to ascii string. See the answer to How do I Encode and Decode a base64 string

//...UPS Shipment Request construction...
shipmentRequest.LabelSpecification.LabelImageFormat.Code = "ZPL";
shipmentRequest.LabelSpecification.LabelStockSize.Height = "8";
shipmentRequest.LabelSpecification.LabelStockSize.Width = "4";
//...
// Submit the Shipment Request to the UPS Ship Service
ShipmentResponse shipmentResponse = shipService.ProcessShipment(shipmentRequest);
//...Process the Shipment Response...

// The Label is encoded as Base64 Text.  Decode this to standard ASCII Text
string labelData = Base64Decode(shipmentResponse.ShipmentResults.PackageResults[0].ShippingLabel.GraphicImage);

// Write the label data to a file so it can be printed/reprinted as needed
System.IO.File.WriteAllText(@"C:\temp\UPSlabel.zpl", labelData);

The ZPL Label should be printed as RAW using a Generic Text printer driver. You can edit and probably print the label using Notepad as long as you turn off its word-wrap, margins, header/footer/page number settings. Notepad++ works.

I think this is also true for UPS EPL formatted labels.

Community
  • 1
  • 1
gridtrak
  • 731
  • 7
  • 20
0

In new versions of their API, they do not have LabelSpecification object so this solution might help you. These settings would help you for a thermal printer:

shipment.Documents = new DocumentsType();
shipment.Documents.Image = new ImageType[1];
shipment.Documents.Image[0] = new ImageType();
shipment.Documents.Image[0].Type = new ShipCodeDescriptionType();
shipment.Documents.Image[0].Type.Code = "30";
shipment.Documents.Image[0].PrintFormat = new ShipCodeDescriptionType();
shipment.Documents.Image[0].PrintFormat.Code = "02"; // thermal
shipment.Documents.Image[0].Format = new ShipCodeDescriptionType();
shipment.Documents.Image[0].Format.Code = "01"; // pdf
shipment.Documents.Image[0].LabelsPerPage = "1";
shipment.Documents.Image[0].PrintSize = new PrintSizeType();
shipment.Documents.Image[0].PrintSize.Length = "4";
shipment.Documents.Image[0].PrintSize.Width = "6";

From above code, you can see because they are accepting an array for image settings, this means it should return multiple images with different specifications.

And this is how I am converting the returned label image and saving it onto the server:

if (!string.IsNullOrEmpty(base64) && !string.IsNullOrEmpty(extension))
{
    byte[] bytes = Convert.FromBase64String(base64);

    var path = "~/ShippingLabels/UPS";

    if (!Directory.Exists(Server.MapPath(path)))
    {
        Directory.CreateDirectory(Server.MapPath(path));
    }

    var filePath = string.Format("{0}/{1}_{2}_{3}.{4}", path, freightShipResponse.ShipmentResults.BOLID, freightShipResponse.ShipmentResults.ShipmentNumber, DateTime.Now.ToString("yyyyMMddmmhhssfff"), extension);

    System.IO.FileStream stream = new FileStream(Server.MapPath(filePath), FileMode.CreateNew);
    System.IO.BinaryWriter writer = new BinaryWriter(stream);
    writer.Write(bytes, 0, bytes.Length);
    writer.Close();
}
Jamshaid K.
  • 3,555
  • 1
  • 27
  • 42