• Eyelash / php jquery image management
  • Magento : display product image on invoice + shipping PDF

    Magento’s wiki has a few articles on the subject of Magento’s PDF generation, which is not very efficient in its default version : one of the main critics I’ve seen is the size of the generated PDF, which can fly to more than 1MB, where a simple font replacement can bring the weight to less than a few KBs ! The subject of the article below is to illustrate how to display images on each line of the generated invoice and shipping PDF.
    The product line display occurs in specific PHP classes within  the app/code/core/Mage/sales/Model/order/pdf folder

    there is one folder for shipment, one for invoice, and one for credit. The product display occurs in the DEfault file where the Mage_Sales_Model_Order_Pdf_Items_Abstract is defined. What I did was simply instanciate a product object using the id from order / items, and get the image file using the following code in the draw function :

    1. //<display image>
    2. $id = Mage::getModel(‘catalog/product’)->getIdBySku($this->getSku($item));
    3. $product=  Mage::getModel(‘catalog/product’)->load($id);
    4. $imageUrl = $product->getSmallImageUrl();
    5. $imageFile=  str_replace(Mage::getBaseUrl(‘media’),"media/",$imageUrl);
    6. // $page->drawText($imageFile , 65, $pdf->y-$shift{1}, ‘UTF-8′);
    7. $imageWidth = 100; $imageHeight = 50;
    8. $image = Zend_Pdf_Image::imageWithPath($imageFile,$imageWidth,$imageHeight);
    9. $y=$pdf->y$imageHeight /3;
    10. $page->drawImage($image, 35,$y, 35+ $imageWidth / 2, $y + $imageHeight/2);
    11. //</display image>
    1. 4 Responses to “Magento : display product image on invoice + shipping PDF”

    2. July 18, 2009 - shanthi

      I have the following code in
      magento-1.3.2.2\magento\app\design\frontend\default\default\template\checkout\cart\item\default.phtml
      $cs = Mage::getModel(‘catalog/product’)->load($_item->getProductId();

      if ($cs->getOptionById($_option['option_id'])->getPriceType() == ‘fixed’)

      {
      //do something here
      }
      The above works perfect for the TEXT type and other field types
      But it does not work for the select drop down custom option
      The value $cs->getOptionById($_option[’option_id’])->getPriceType() is empty for the select custom option
      Can anyone point me how to make it work for drop down option too ?
      Shanthi

    3. January 18, 2010 - Neil

      Hi there,

      I was wondering if you could perhaps explain a bit more with those code gets added?

      Thanks. :)

    4. January 29, 2010 - Jhansi

      Hi,

      I have added this code in invoice.php,but product image is not shown in invoice..

      How to proceed with this issue.

      Jhansi.

    5. May 10, 2010 - Thillai

      Hi

      I have created a new transactional email template for my website for processed status .

      I would like to edit some values dynamically in the email template.

      Could please tell me on which file(*.phtml) i have to make my changes.

      Please help me how to resolve this issue as early as possible.

    Quick contact form