Display product image in invoice + Magento

Home / Magento / Display product image in invoice + Magento

Here I show you how to Display product image in magento PDF invoice or Display product image in shipping invoice.

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 deault file where the Mage_Sales_Model_Order_Pdf_Items_Abstract is defined. Product object using the id from order / items, and get the image file using the following code in the draw function.

/* Display Image Start */
$id = Mage::getModel('catalog/product')->getIdBySku($this->getSku($item));
$product=  Mage::getModel('catalog/product')->load($id);
$imageUrl = $product->getSmallImageUrl();
$imageFile=  str_replace(Mage::getBaseUrl('media'),"media/",$imageUrl);
$imageWidth = 100; $imageHeight = 50;
$image = Zend_Pdf_Image::imageWithPath($imageFile,$imageWidth,$imageHeight);
$y=$pdf->y – $imageHeight /3;
$page->drawImage($image, 35,$y, 35+ $imageWidth / 2, $y + $imageHeight/2);

// If you want to display custom image then use this code
$image = Mage::getBaseDir('media') . '/sales/store/logo/default/custom_image.jpg';
if (is_file($image)) {
	$imageWidth = 812; $imageHeight = 450;
	$image = Zend_Pdf_Image::imageWithPath($image,$imageWidth,$imageHeight);
	$y=$imageHeight /2.5;
	$page->drawImage($image, 35,$y, 35+ $imageWidth / 1.5, $y + $imageHeight/2);

/* Display Image End */

Leave a Reply

Your email address will not be published. Required fields are marked *