0

Any ideas where and how I can change the size of the generated labels for UPS? We're getting giant labels that are unusable.

4

By default there is no way to resize UPS Label size in Magento as Magento get Label Image Format in GIF and creating PDF from that.

UPS API provide option to get Label Image Format in GIF or Thermal print format (EPL2,ZPL,STARPL,SPL)

For GIF format there is no any options to pass label size,however for Thermal print type, API provide options for Height and Width of label size.

<LabelStockSize>
    <Height>6</Height>
    <Width>4</Width>
</LabelStockSize> 

Yo can get Label in 6x4 or 8x4 INCH. For This you need to create custom module that override UPS function. You can find code for API in class

Mage_Usa_Model_Shipping_Carrier_Ups

at

app/code/core/Mage/Usa/Model/Shipping/Carrier/Ups.php

and method name _formShipmentRequest()

Hope this will help

1

You need to change into system.xml file which generate the label tags for any shipping method in magento. Please go tho the follow path where you will able to add or remove the labels for ups shipping method.

magento\app\code\core\Mage\Usa\etc\system.xml
  • thanks, but not looking to add or remove labels, just to make the size half of an 8.5 x 11 inch sheet of paper. Right now the size is 20 x 30 so it's really annoying to have to resize constantly in the printer screen. – mel Jul 10 '14 at 15:11
  • @mel Please share the screenshot where you find the issue. – TBI Infotech Jul 10 '14 at 15:12
  • Not really able to share a screen shot, it's the pdf that is generated when you create the ups shipping label. – mel Jul 15 '14 at 16:45
1

I know this question if for Magento 1.

But I faced on a similar problem in Magento 2 UPS label in PDF format from a GIF image.

The requested size for my customer is 4" / 6".

You need to find the function in Magento where Magento generate the PDF from the UPS gif label image.

Then you can rewrite the PDF_Page size to your dimension.

In magento 2 it is located here : vendor/magento/module-shipping/Model/Shipping/LabelGenerator.php:141

For example, in my case I did this :

    // FORCE Resize for UPS label PDF : size is in point (72 * inch)
    $xSizeResized = 6 * 72;
    $ySizeResized = 4 * 72;

    $page->drawImage($pdfImage, 0, 0, $xSizeResized, $ySizeResized);

For magento 1, it is located here : app/code/core/Mage/Adminhtml/controllers/Sales/Order/ShipmentController.php:712

Update this function

/**
 * Create Zend_Pdf_Page instance with image from $imageString. Supports JPEG, PNG, GIF, WBMP, and GD2 formats.
 *
 * @param string $imageString
 * @return Zend_Pdf_Page|bool
 */
protected function _createPdfPageFromImageString($imageString)
{
    $image = imagecreatefromstring($imageString);
    if (!$image) {
        return false;
    }
    // Force RESIZE FOR UPS
    $xSize = 6 * 72;
    $ySize = 4 * 72;
    $page = new Zend_Pdf_Page($xSize, $ySize);
    imageinterlace($image, 0);
    $tmpFileName = sys_get_temp_dir() . DS . 'shipping_labels_'
                 . uniqid(mt_rand()) . time() . '.png';
    imagepng($image, $tmpFileName);
    $pdfImage = Zend_Pdf_Image::imageWithPath($tmpFileName);
    $page->drawImage($pdfImage, 0, 0, $xSize, $ySize);
    unlink($tmpFileName);
    return $page;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.