Product Image in invoice email template Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?how to display product image in sales/order/view/ pageMagento 2 product image in new order emailHow can I get product list with its detail in rest API I'm on magento2Area code not setProduct Image does not load on product pageModel class not found in …/magento/framework/ObjectManager/Factory/AbstractFactory.php:93Magento 2: Products images are not showing on category pageM2 - disappearing image after(Solved) Magento 2, Add product image in all transaction emails(shipment, invoice, credit memo)Magento 2 get custom attribute of a single product inside a pluginGetting Errors after MySQL database importMsrpPriceCalculator Exception

When speaking, how do you change your mind mid-sentence?

Is Vivien of the Wilds + Wilderness Reclamation a competitive combo?

enable https on private network

Does using the Inspiration rules for character defects encourage My Guy Syndrome?

When does Bran Stark remember Jamie pushing him?

Indexes with the same object_id but different names

Can I take recommendation from someone I met at a conference?

How can I wire a 9-position switch so that each position turns on one more LED than the one before?

Is it accepted to use working hours to read general interest books?

Lights are flickering on and off after accidentally bumping into light switch

If gravity precedes the formation of a solar system, where did the mass come from that caused the gravity?

Why do C and C++ allow the expression (int) + 4*5?

Why aren't these two solutions equivalent? Combinatorics problem

FME Console for testing

Why do people think Winterfell crypts is the safest place for women, children & old people?

What is the definining line between a helicopter and a drone a person can ride in?

Is "ein Herz wie das meine" an antiquated or colloquial use of the possesive pronoun?

How can I delete rows in the text?

What's the connection between Mr. Nancy and fried chicken?

Output the slug and name of a CPT single post taxonomy term

Determinant of a matrix with 2 equal rows

How to ask rejected full-time candidates to apply to teach individual courses?

Can this water damage be explained by lack of gutters and grading issues?

How was Lagrange appointed professor of mathematics so early?



Product Image in invoice email template



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?how to display product image in sales/order/view/ pageMagento 2 product image in new order emailHow can I get product list with its detail in rest API I'm on magento2Area code not setProduct Image does not load on product pageModel class not found in …/magento/framework/ObjectManager/Factory/AbstractFactory.php:93Magento 2: Products images are not showing on category pageM2 - disappearing image after(Solved) Magento 2, Add product image in all transaction emails(shipment, invoice, credit memo)Magento 2 get custom attribute of a single product inside a pluginGetting Errors after MySQL database importMsrpPriceCalculator Exception



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








11















I am trying to get product images for invoice email template. I used below code. But I am only getting Magento placeholder image in email template.



<td>
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product_id = $_item->getOrderItem()->getProduct();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);

$_imagehelper = $objectManager->get('MagentoCatalogHelperImage');
$image_url = $_imagehelper->init($product, 'cart_page_product_thumbnail')->getUrl();

?>
<img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />
</td>









share|improve this question
























  • you can't use PHP in email templates

    – Philipp Sander
    Mar 21 at 7:13











  • i did not use in my email template directly, i added this code in my file "Magento_Sales/templates/email/items/shipment/default.phtml"

    – mohana
    Mar 21 at 7:54











  • Do you mean the order email?

    – Dava Gordon
    Apr 12 at 10:57











  • Try the below answer and keep post your complete phtml

    – Prathap Gunasekaran
    Apr 13 at 3:24

















11















I am trying to get product images for invoice email template. I used below code. But I am only getting Magento placeholder image in email template.



<td>
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product_id = $_item->getOrderItem()->getProduct();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);

$_imagehelper = $objectManager->get('MagentoCatalogHelperImage');
$image_url = $_imagehelper->init($product, 'cart_page_product_thumbnail')->getUrl();

?>
<img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />
</td>









share|improve this question
























  • you can't use PHP in email templates

    – Philipp Sander
    Mar 21 at 7:13











  • i did not use in my email template directly, i added this code in my file "Magento_Sales/templates/email/items/shipment/default.phtml"

    – mohana
    Mar 21 at 7:54











  • Do you mean the order email?

    – Dava Gordon
    Apr 12 at 10:57











  • Try the below answer and keep post your complete phtml

    – Prathap Gunasekaran
    Apr 13 at 3:24













11












11








11


2






I am trying to get product images for invoice email template. I used below code. But I am only getting Magento placeholder image in email template.



<td>
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product_id = $_item->getOrderItem()->getProduct();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);

$_imagehelper = $objectManager->get('MagentoCatalogHelperImage');
$image_url = $_imagehelper->init($product, 'cart_page_product_thumbnail')->getUrl();

?>
<img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />
</td>









share|improve this question
















I am trying to get product images for invoice email template. I used below code. But I am only getting Magento placeholder image in email template.



<td>
<?php
$objectManager = MagentoFrameworkAppObjectManager::getInstance();
$product_id = $_item->getOrderItem()->getProduct();
$product = $objectManager->get('MagentoCatalogModelProduct')->load($product_id);

$_imagehelper = $objectManager->get('MagentoCatalogHelperImage');
$image_url = $_imagehelper->init($product, 'cart_page_product_thumbnail')->getUrl();

?>
<img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />
</td>






magento2 placeholder-image sales-invoice






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 12 at 10:24









Jaimin Sutariya

9,47122055




9,47122055










asked Mar 21 at 6:20









mohanamohana

8214




8214












  • you can't use PHP in email templates

    – Philipp Sander
    Mar 21 at 7:13











  • i did not use in my email template directly, i added this code in my file "Magento_Sales/templates/email/items/shipment/default.phtml"

    – mohana
    Mar 21 at 7:54











  • Do you mean the order email?

    – Dava Gordon
    Apr 12 at 10:57











  • Try the below answer and keep post your complete phtml

    – Prathap Gunasekaran
    Apr 13 at 3:24

















  • you can't use PHP in email templates

    – Philipp Sander
    Mar 21 at 7:13











  • i did not use in my email template directly, i added this code in my file "Magento_Sales/templates/email/items/shipment/default.phtml"

    – mohana
    Mar 21 at 7:54











  • Do you mean the order email?

    – Dava Gordon
    Apr 12 at 10:57











  • Try the below answer and keep post your complete phtml

    – Prathap Gunasekaran
    Apr 13 at 3:24
















you can't use PHP in email templates

– Philipp Sander
Mar 21 at 7:13





you can't use PHP in email templates

– Philipp Sander
Mar 21 at 7:13













i did not use in my email template directly, i added this code in my file "Magento_Sales/templates/email/items/shipment/default.phtml"

– mohana
Mar 21 at 7:54





i did not use in my email template directly, i added this code in my file "Magento_Sales/templates/email/items/shipment/default.phtml"

– mohana
Mar 21 at 7:54













Do you mean the order email?

– Dava Gordon
Apr 12 at 10:57





Do you mean the order email?

– Dava Gordon
Apr 12 at 10:57













Try the below answer and keep post your complete phtml

– Prathap Gunasekaran
Apr 13 at 3:24





Try the below answer and keep post your complete phtml

– Prathap Gunasekaran
Apr 13 at 3:24










4 Answers
4






active

oldest

votes


















3














I found the solution but it's getting parent thumbnail image, i like to get if product has selected in swatch option, that swatch option need to display.



example: if i select red colour, red colour swatch image need to display.




$productId = $_item->getProductId();
$objectManagerHere = MagentoFrameworkAppObjectManager::getInstance();
$product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);

$_objectManager = MagentoFrameworkAppObjectManager::getInstance();
$imageHelper = $_objectManager->get('MagentoCatalogHelperImage');
$image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize(80, 80)->getUrl();

<img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />





share|improve this answer
































    3





    +50









    I have override DefaultInvoice



    class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice

    public function draw()

    $order = $this->getOrder();
    $item = $this->getItem();
    $pdf = $this->getPdf();
    $page = $this->getPage();
    $lines = [];


    // draw Product image
    $productImage = $this->getProductImage($item, $page);

    // draw Product name
    $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];

    $lines[0][] = array(
    'text' => $productImage,
    'is_image' => 1,
    'feed' => 200
    );

    // draw SKU
    $lines[0][] = [
    'text' => $this->string->split($this->getSku($item), 17),
    'feed' => 370,
    'align' => 'right',
    ];

    // draw QTY
    $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];

    // draw item Prices
    $i = 0;
    $prices = $this->getItemPricesForDisplay();
    $feedPrice = 425;
    $feedSubtotal = $feedPrice + 140;
    foreach ($prices as $priceData)
    if (isset($priceData['label']))
    // draw Price label
    $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
    // draw Subtotal label
    $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
    $i++;

    // draw Price
    $lines[$i][] = [
    'text' => $priceData['price'],
    'feed' => $feedPrice,
    'font' => 'bold',
    'align' => 'right',
    ];
    // draw Subtotal
    $lines[$i][] = [
    'text' => $priceData['subtotal'],
    'feed' => $feedSubtotal,
    'font' => 'bold',
    'align' => 'right',
    ];
    $i++;


    // draw Tax
    $lines[0][] = [
    'text' => $order->formatPriceTxt($item->getTaxAmount()),
    'feed' => 515,
    'font' => 'bold',
    'align' => 'right',
    ];

    // custom options
    $options = $this->getItemOptions();
    if ($options)
    foreach ($options as $option)
    // draw options label
    $lines[][] = [
    'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
    'font' => 'italic',
    'feed' => 35,
    ];

    if ($option['value'])
    if (isset($option['print_value']))
    $printValue = $option['print_value'];
    else
    $printValue = $this->filterManager->stripTags($option['value']);

    $values = explode(', ', $printValue);
    foreach ($values as $value)
    $lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];





    $lineBlock = ['lines' => $lines, 'height' => 20];

    $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);

    $this->setPage($page);



    /*
    * Return Value of custom attribute
    * */
    private function getProductImage($item, &$page)

    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $productId = $item->getOrderItem()->getProductId();
    $image = $objectManager->get('MagentoCatalogModelProduct')->load($productId);

    if (!is_null($image))
    try

    $imagePath = '/catalog/product/'.$image->getSmallImage();

    $filesystem = $objectManager->get('MagentoFrameworkFilesystem');
    $media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);

    if ($media_dir->isFile($imagePath))
    return $media_dir->getAbsolutePath($imagePath);

    else
    return null;

    catch (Exception $e)
    return false;







    Which returns me PDF like this. (working on Image rotation :) )




    enter image description here



    UPDATED




    For variant based product - based on configure product's attribute
    selection




    class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice

    public function draw()

    $order = $this->getOrder();
    $item = $this->getItem();
    $pdf = $this->getPdf();
    $page = $this->getPage();
    $lines = [];


    // draw Product image
    $productImage = $this->getProductImage($item, $page);

    // draw Product name
    $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];

    $lines[0][] = array(
    'text' => $productImage,
    'is_image' => 1,
    'feed' => 200
    );

    // draw SKU
    $lines[0][] = [
    'text' => $this->string->split($this->getSku($item), 17),
    'feed' => 370,
    'align' => 'right',
    ];

    // draw QTY
    $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];

    // draw item Prices
    $i = 0;
    $prices = $this->getItemPricesForDisplay();
    $feedPrice = 425;
    $feedSubtotal = $feedPrice + 140;
    foreach ($prices as $priceData)
    if (isset($priceData['label']))
    // draw Price label
    $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
    // draw Subtotal label
    $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
    $i++;

    // draw Price
    $lines[$i][] = [
    'text' => $priceData['price'],
    'feed' => $feedPrice,
    'font' => 'bold',
    'align' => 'right',
    ];
    // draw Subtotal
    $lines[$i][] = [
    'text' => $priceData['subtotal'],
    'feed' => $feedSubtotal,
    'font' => 'bold',
    'align' => 'right',
    ];
    $i++;


    // draw Tax
    $lines[0][] = [
    'text' => $order->formatPriceTxt($item->getTaxAmount()),
    'feed' => 515,
    'font' => 'bold',
    'align' => 'right',
    ];

    // custom options
    $options = $this->getItemOptions();
    if ($options)
    foreach ($options as $option)
    // draw options label
    $lines[][] = [
    'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
    'font' => 'italic',
    'feed' => 35,
    ];

    if ($option['value'])
    if (isset($option['print_value']))
    $printValue = $option['print_value'];
    else
    $printValue = $this->filterManager->stripTags($option['value']);

    $values = explode(', ', $printValue);
    foreach ($values as $value)
    $lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];





    $lineBlock = ['lines' => $lines, 'height' => 20];

    $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);

    $this->setPage($page);



    /*
    * Return Value of custom attribute
    * */
    private function getProductImage($item, &$page)

    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
    $productId = $item->getOrderItem()->getProductId();
    $data = $objectManager->get('MagentoCatalogModelProductRepository')->get($item->getSku());
    $image = $data->getImage();

    if (!is_null($image))
    try

    $imagePath = '/catalog/product/'.$image;

    $filesystem = $objectManager->get('MagentoFrameworkFilesystem');
    $media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);

    if ($media_dir->isFile($imagePath))
    return $media_dir->getAbsolutePath($imagePath);

    else
    return null;

    catch (Exception $e)
    return false;







    Here's simple product's image in Invoice based of variant selection of
    configure product.




    enter image description here



    More References



    Reference 1 , Reference 2 , Reference 3






    share|improve this answer
































      0














      You can replace following line in your code



      $product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);


      With following line



      $product = $objectManagerHere->get('MagentoCatalogModelProductRepository')->get($_item->getSku());


      With this, you can get appropriate simple product of configurable product.






      share|improve this answer






























        0














        I think you should try with cart_page_product_thumbnail instead of product_thumbnail_image in your get product image code.



        Your code should be like this.



        $image_url = $imageHelper->init($product, 'cart_page_product_thumbnail')->setImageFile($product->getFile())->resize(80, 80)->getUrl();


        I have used the above code to display product image in the Email template and it is working fine with configurable products. and I think it also works for the invoice email template.



        I have also seen so many users use cart_page_product_thumbnail please check below reference link.



        • Product image in-new order email

        • Display product image in sales order view-page

        I hope it helps!






        share|improve this answer























          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "479"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266775%2fproduct-image-in-invoice-email-template%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          I found the solution but it's getting parent thumbnail image, i like to get if product has selected in swatch option, that swatch option need to display.



          example: if i select red colour, red colour swatch image need to display.




          $productId = $_item->getProductId();
          $objectManagerHere = MagentoFrameworkAppObjectManager::getInstance();
          $product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);

          $_objectManager = MagentoFrameworkAppObjectManager::getInstance();
          $imageHelper = $_objectManager->get('MagentoCatalogHelperImage');
          $image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize(80, 80)->getUrl();

          <img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />





          share|improve this answer





























            3














            I found the solution but it's getting parent thumbnail image, i like to get if product has selected in swatch option, that swatch option need to display.



            example: if i select red colour, red colour swatch image need to display.




            $productId = $_item->getProductId();
            $objectManagerHere = MagentoFrameworkAppObjectManager::getInstance();
            $product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);

            $_objectManager = MagentoFrameworkAppObjectManager::getInstance();
            $imageHelper = $_objectManager->get('MagentoCatalogHelperImage');
            $image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize(80, 80)->getUrl();

            <img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />





            share|improve this answer



























              3












              3








              3







              I found the solution but it's getting parent thumbnail image, i like to get if product has selected in swatch option, that swatch option need to display.



              example: if i select red colour, red colour swatch image need to display.




              $productId = $_item->getProductId();
              $objectManagerHere = MagentoFrameworkAppObjectManager::getInstance();
              $product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);

              $_objectManager = MagentoFrameworkAppObjectManager::getInstance();
              $imageHelper = $_objectManager->get('MagentoCatalogHelperImage');
              $image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize(80, 80)->getUrl();

              <img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />





              share|improve this answer















              I found the solution but it's getting parent thumbnail image, i like to get if product has selected in swatch option, that swatch option need to display.



              example: if i select red colour, red colour swatch image need to display.




              $productId = $_item->getProductId();
              $objectManagerHere = MagentoFrameworkAppObjectManager::getInstance();
              $product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);

              $_objectManager = MagentoFrameworkAppObjectManager::getInstance();
              $imageHelper = $_objectManager->get('MagentoCatalogHelperImage');
              $image_url = $imageHelper->init($product, 'product_thumbnail_image')->setImageFile($product->getFile())->resize(80, 80)->getUrl();

              <img src="<?php echo $image_url; ?>" alt="<?php echo $product->getName(); ?>" />






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Apr 12 at 6:57

























              answered Mar 21 at 9:06









              mohanamohana

              8214




              8214























                  3





                  +50









                  I have override DefaultInvoice



                  class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice

                  public function draw()

                  $order = $this->getOrder();
                  $item = $this->getItem();
                  $pdf = $this->getPdf();
                  $page = $this->getPage();
                  $lines = [];


                  // draw Product image
                  $productImage = $this->getProductImage($item, $page);

                  // draw Product name
                  $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];

                  $lines[0][] = array(
                  'text' => $productImage,
                  'is_image' => 1,
                  'feed' => 200
                  );

                  // draw SKU
                  $lines[0][] = [
                  'text' => $this->string->split($this->getSku($item), 17),
                  'feed' => 370,
                  'align' => 'right',
                  ];

                  // draw QTY
                  $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];

                  // draw item Prices
                  $i = 0;
                  $prices = $this->getItemPricesForDisplay();
                  $feedPrice = 425;
                  $feedSubtotal = $feedPrice + 140;
                  foreach ($prices as $priceData)
                  if (isset($priceData['label']))
                  // draw Price label
                  $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
                  // draw Subtotal label
                  $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
                  $i++;

                  // draw Price
                  $lines[$i][] = [
                  'text' => $priceData['price'],
                  'feed' => $feedPrice,
                  'font' => 'bold',
                  'align' => 'right',
                  ];
                  // draw Subtotal
                  $lines[$i][] = [
                  'text' => $priceData['subtotal'],
                  'feed' => $feedSubtotal,
                  'font' => 'bold',
                  'align' => 'right',
                  ];
                  $i++;


                  // draw Tax
                  $lines[0][] = [
                  'text' => $order->formatPriceTxt($item->getTaxAmount()),
                  'feed' => 515,
                  'font' => 'bold',
                  'align' => 'right',
                  ];

                  // custom options
                  $options = $this->getItemOptions();
                  if ($options)
                  foreach ($options as $option)
                  // draw options label
                  $lines[][] = [
                  'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
                  'font' => 'italic',
                  'feed' => 35,
                  ];

                  if ($option['value'])
                  if (isset($option['print_value']))
                  $printValue = $option['print_value'];
                  else
                  $printValue = $this->filterManager->stripTags($option['value']);

                  $values = explode(', ', $printValue);
                  foreach ($values as $value)
                  $lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];





                  $lineBlock = ['lines' => $lines, 'height' => 20];

                  $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);

                  $this->setPage($page);



                  /*
                  * Return Value of custom attribute
                  * */
                  private function getProductImage($item, &$page)

                  $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                  $productId = $item->getOrderItem()->getProductId();
                  $image = $objectManager->get('MagentoCatalogModelProduct')->load($productId);

                  if (!is_null($image))
                  try

                  $imagePath = '/catalog/product/'.$image->getSmallImage();

                  $filesystem = $objectManager->get('MagentoFrameworkFilesystem');
                  $media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);

                  if ($media_dir->isFile($imagePath))
                  return $media_dir->getAbsolutePath($imagePath);

                  else
                  return null;

                  catch (Exception $e)
                  return false;







                  Which returns me PDF like this. (working on Image rotation :) )




                  enter image description here



                  UPDATED




                  For variant based product - based on configure product's attribute
                  selection




                  class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice

                  public function draw()

                  $order = $this->getOrder();
                  $item = $this->getItem();
                  $pdf = $this->getPdf();
                  $page = $this->getPage();
                  $lines = [];


                  // draw Product image
                  $productImage = $this->getProductImage($item, $page);

                  // draw Product name
                  $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];

                  $lines[0][] = array(
                  'text' => $productImage,
                  'is_image' => 1,
                  'feed' => 200
                  );

                  // draw SKU
                  $lines[0][] = [
                  'text' => $this->string->split($this->getSku($item), 17),
                  'feed' => 370,
                  'align' => 'right',
                  ];

                  // draw QTY
                  $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];

                  // draw item Prices
                  $i = 0;
                  $prices = $this->getItemPricesForDisplay();
                  $feedPrice = 425;
                  $feedSubtotal = $feedPrice + 140;
                  foreach ($prices as $priceData)
                  if (isset($priceData['label']))
                  // draw Price label
                  $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
                  // draw Subtotal label
                  $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
                  $i++;

                  // draw Price
                  $lines[$i][] = [
                  'text' => $priceData['price'],
                  'feed' => $feedPrice,
                  'font' => 'bold',
                  'align' => 'right',
                  ];
                  // draw Subtotal
                  $lines[$i][] = [
                  'text' => $priceData['subtotal'],
                  'feed' => $feedSubtotal,
                  'font' => 'bold',
                  'align' => 'right',
                  ];
                  $i++;


                  // draw Tax
                  $lines[0][] = [
                  'text' => $order->formatPriceTxt($item->getTaxAmount()),
                  'feed' => 515,
                  'font' => 'bold',
                  'align' => 'right',
                  ];

                  // custom options
                  $options = $this->getItemOptions();
                  if ($options)
                  foreach ($options as $option)
                  // draw options label
                  $lines[][] = [
                  'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
                  'font' => 'italic',
                  'feed' => 35,
                  ];

                  if ($option['value'])
                  if (isset($option['print_value']))
                  $printValue = $option['print_value'];
                  else
                  $printValue = $this->filterManager->stripTags($option['value']);

                  $values = explode(', ', $printValue);
                  foreach ($values as $value)
                  $lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];





                  $lineBlock = ['lines' => $lines, 'height' => 20];

                  $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);

                  $this->setPage($page);



                  /*
                  * Return Value of custom attribute
                  * */
                  private function getProductImage($item, &$page)

                  $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                  $productId = $item->getOrderItem()->getProductId();
                  $data = $objectManager->get('MagentoCatalogModelProductRepository')->get($item->getSku());
                  $image = $data->getImage();

                  if (!is_null($image))
                  try

                  $imagePath = '/catalog/product/'.$image;

                  $filesystem = $objectManager->get('MagentoFrameworkFilesystem');
                  $media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);

                  if ($media_dir->isFile($imagePath))
                  return $media_dir->getAbsolutePath($imagePath);

                  else
                  return null;

                  catch (Exception $e)
                  return false;







                  Here's simple product's image in Invoice based of variant selection of
                  configure product.




                  enter image description here



                  More References



                  Reference 1 , Reference 2 , Reference 3






                  share|improve this answer





























                    3





                    +50









                    I have override DefaultInvoice



                    class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice

                    public function draw()

                    $order = $this->getOrder();
                    $item = $this->getItem();
                    $pdf = $this->getPdf();
                    $page = $this->getPage();
                    $lines = [];


                    // draw Product image
                    $productImage = $this->getProductImage($item, $page);

                    // draw Product name
                    $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];

                    $lines[0][] = array(
                    'text' => $productImage,
                    'is_image' => 1,
                    'feed' => 200
                    );

                    // draw SKU
                    $lines[0][] = [
                    'text' => $this->string->split($this->getSku($item), 17),
                    'feed' => 370,
                    'align' => 'right',
                    ];

                    // draw QTY
                    $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];

                    // draw item Prices
                    $i = 0;
                    $prices = $this->getItemPricesForDisplay();
                    $feedPrice = 425;
                    $feedSubtotal = $feedPrice + 140;
                    foreach ($prices as $priceData)
                    if (isset($priceData['label']))
                    // draw Price label
                    $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
                    // draw Subtotal label
                    $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
                    $i++;

                    // draw Price
                    $lines[$i][] = [
                    'text' => $priceData['price'],
                    'feed' => $feedPrice,
                    'font' => 'bold',
                    'align' => 'right',
                    ];
                    // draw Subtotal
                    $lines[$i][] = [
                    'text' => $priceData['subtotal'],
                    'feed' => $feedSubtotal,
                    'font' => 'bold',
                    'align' => 'right',
                    ];
                    $i++;


                    // draw Tax
                    $lines[0][] = [
                    'text' => $order->formatPriceTxt($item->getTaxAmount()),
                    'feed' => 515,
                    'font' => 'bold',
                    'align' => 'right',
                    ];

                    // custom options
                    $options = $this->getItemOptions();
                    if ($options)
                    foreach ($options as $option)
                    // draw options label
                    $lines[][] = [
                    'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
                    'font' => 'italic',
                    'feed' => 35,
                    ];

                    if ($option['value'])
                    if (isset($option['print_value']))
                    $printValue = $option['print_value'];
                    else
                    $printValue = $this->filterManager->stripTags($option['value']);

                    $values = explode(', ', $printValue);
                    foreach ($values as $value)
                    $lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];





                    $lineBlock = ['lines' => $lines, 'height' => 20];

                    $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);

                    $this->setPage($page);



                    /*
                    * Return Value of custom attribute
                    * */
                    private function getProductImage($item, &$page)

                    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                    $productId = $item->getOrderItem()->getProductId();
                    $image = $objectManager->get('MagentoCatalogModelProduct')->load($productId);

                    if (!is_null($image))
                    try

                    $imagePath = '/catalog/product/'.$image->getSmallImage();

                    $filesystem = $objectManager->get('MagentoFrameworkFilesystem');
                    $media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);

                    if ($media_dir->isFile($imagePath))
                    return $media_dir->getAbsolutePath($imagePath);

                    else
                    return null;

                    catch (Exception $e)
                    return false;







                    Which returns me PDF like this. (working on Image rotation :) )




                    enter image description here



                    UPDATED




                    For variant based product - based on configure product's attribute
                    selection




                    class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice

                    public function draw()

                    $order = $this->getOrder();
                    $item = $this->getItem();
                    $pdf = $this->getPdf();
                    $page = $this->getPage();
                    $lines = [];


                    // draw Product image
                    $productImage = $this->getProductImage($item, $page);

                    // draw Product name
                    $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];

                    $lines[0][] = array(
                    'text' => $productImage,
                    'is_image' => 1,
                    'feed' => 200
                    );

                    // draw SKU
                    $lines[0][] = [
                    'text' => $this->string->split($this->getSku($item), 17),
                    'feed' => 370,
                    'align' => 'right',
                    ];

                    // draw QTY
                    $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];

                    // draw item Prices
                    $i = 0;
                    $prices = $this->getItemPricesForDisplay();
                    $feedPrice = 425;
                    $feedSubtotal = $feedPrice + 140;
                    foreach ($prices as $priceData)
                    if (isset($priceData['label']))
                    // draw Price label
                    $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
                    // draw Subtotal label
                    $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
                    $i++;

                    // draw Price
                    $lines[$i][] = [
                    'text' => $priceData['price'],
                    'feed' => $feedPrice,
                    'font' => 'bold',
                    'align' => 'right',
                    ];
                    // draw Subtotal
                    $lines[$i][] = [
                    'text' => $priceData['subtotal'],
                    'feed' => $feedSubtotal,
                    'font' => 'bold',
                    'align' => 'right',
                    ];
                    $i++;


                    // draw Tax
                    $lines[0][] = [
                    'text' => $order->formatPriceTxt($item->getTaxAmount()),
                    'feed' => 515,
                    'font' => 'bold',
                    'align' => 'right',
                    ];

                    // custom options
                    $options = $this->getItemOptions();
                    if ($options)
                    foreach ($options as $option)
                    // draw options label
                    $lines[][] = [
                    'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
                    'font' => 'italic',
                    'feed' => 35,
                    ];

                    if ($option['value'])
                    if (isset($option['print_value']))
                    $printValue = $option['print_value'];
                    else
                    $printValue = $this->filterManager->stripTags($option['value']);

                    $values = explode(', ', $printValue);
                    foreach ($values as $value)
                    $lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];





                    $lineBlock = ['lines' => $lines, 'height' => 20];

                    $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);

                    $this->setPage($page);



                    /*
                    * Return Value of custom attribute
                    * */
                    private function getProductImage($item, &$page)

                    $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                    $productId = $item->getOrderItem()->getProductId();
                    $data = $objectManager->get('MagentoCatalogModelProductRepository')->get($item->getSku());
                    $image = $data->getImage();

                    if (!is_null($image))
                    try

                    $imagePath = '/catalog/product/'.$image;

                    $filesystem = $objectManager->get('MagentoFrameworkFilesystem');
                    $media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);

                    if ($media_dir->isFile($imagePath))
                    return $media_dir->getAbsolutePath($imagePath);

                    else
                    return null;

                    catch (Exception $e)
                    return false;







                    Here's simple product's image in Invoice based of variant selection of
                    configure product.




                    enter image description here



                    More References



                    Reference 1 , Reference 2 , Reference 3






                    share|improve this answer



























                      3





                      +50







                      3





                      +50



                      3




                      +50





                      I have override DefaultInvoice



                      class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice

                      public function draw()

                      $order = $this->getOrder();
                      $item = $this->getItem();
                      $pdf = $this->getPdf();
                      $page = $this->getPage();
                      $lines = [];


                      // draw Product image
                      $productImage = $this->getProductImage($item, $page);

                      // draw Product name
                      $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];

                      $lines[0][] = array(
                      'text' => $productImage,
                      'is_image' => 1,
                      'feed' => 200
                      );

                      // draw SKU
                      $lines[0][] = [
                      'text' => $this->string->split($this->getSku($item), 17),
                      'feed' => 370,
                      'align' => 'right',
                      ];

                      // draw QTY
                      $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];

                      // draw item Prices
                      $i = 0;
                      $prices = $this->getItemPricesForDisplay();
                      $feedPrice = 425;
                      $feedSubtotal = $feedPrice + 140;
                      foreach ($prices as $priceData)
                      if (isset($priceData['label']))
                      // draw Price label
                      $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
                      // draw Subtotal label
                      $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
                      $i++;

                      // draw Price
                      $lines[$i][] = [
                      'text' => $priceData['price'],
                      'feed' => $feedPrice,
                      'font' => 'bold',
                      'align' => 'right',
                      ];
                      // draw Subtotal
                      $lines[$i][] = [
                      'text' => $priceData['subtotal'],
                      'feed' => $feedSubtotal,
                      'font' => 'bold',
                      'align' => 'right',
                      ];
                      $i++;


                      // draw Tax
                      $lines[0][] = [
                      'text' => $order->formatPriceTxt($item->getTaxAmount()),
                      'feed' => 515,
                      'font' => 'bold',
                      'align' => 'right',
                      ];

                      // custom options
                      $options = $this->getItemOptions();
                      if ($options)
                      foreach ($options as $option)
                      // draw options label
                      $lines[][] = [
                      'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
                      'font' => 'italic',
                      'feed' => 35,
                      ];

                      if ($option['value'])
                      if (isset($option['print_value']))
                      $printValue = $option['print_value'];
                      else
                      $printValue = $this->filterManager->stripTags($option['value']);

                      $values = explode(', ', $printValue);
                      foreach ($values as $value)
                      $lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];





                      $lineBlock = ['lines' => $lines, 'height' => 20];

                      $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);

                      $this->setPage($page);



                      /*
                      * Return Value of custom attribute
                      * */
                      private function getProductImage($item, &$page)

                      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                      $productId = $item->getOrderItem()->getProductId();
                      $image = $objectManager->get('MagentoCatalogModelProduct')->load($productId);

                      if (!is_null($image))
                      try

                      $imagePath = '/catalog/product/'.$image->getSmallImage();

                      $filesystem = $objectManager->get('MagentoFrameworkFilesystem');
                      $media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);

                      if ($media_dir->isFile($imagePath))
                      return $media_dir->getAbsolutePath($imagePath);

                      else
                      return null;

                      catch (Exception $e)
                      return false;







                      Which returns me PDF like this. (working on Image rotation :) )




                      enter image description here



                      UPDATED




                      For variant based product - based on configure product's attribute
                      selection




                      class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice

                      public function draw()

                      $order = $this->getOrder();
                      $item = $this->getItem();
                      $pdf = $this->getPdf();
                      $page = $this->getPage();
                      $lines = [];


                      // draw Product image
                      $productImage = $this->getProductImage($item, $page);

                      // draw Product name
                      $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];

                      $lines[0][] = array(
                      'text' => $productImage,
                      'is_image' => 1,
                      'feed' => 200
                      );

                      // draw SKU
                      $lines[0][] = [
                      'text' => $this->string->split($this->getSku($item), 17),
                      'feed' => 370,
                      'align' => 'right',
                      ];

                      // draw QTY
                      $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];

                      // draw item Prices
                      $i = 0;
                      $prices = $this->getItemPricesForDisplay();
                      $feedPrice = 425;
                      $feedSubtotal = $feedPrice + 140;
                      foreach ($prices as $priceData)
                      if (isset($priceData['label']))
                      // draw Price label
                      $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
                      // draw Subtotal label
                      $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
                      $i++;

                      // draw Price
                      $lines[$i][] = [
                      'text' => $priceData['price'],
                      'feed' => $feedPrice,
                      'font' => 'bold',
                      'align' => 'right',
                      ];
                      // draw Subtotal
                      $lines[$i][] = [
                      'text' => $priceData['subtotal'],
                      'feed' => $feedSubtotal,
                      'font' => 'bold',
                      'align' => 'right',
                      ];
                      $i++;


                      // draw Tax
                      $lines[0][] = [
                      'text' => $order->formatPriceTxt($item->getTaxAmount()),
                      'feed' => 515,
                      'font' => 'bold',
                      'align' => 'right',
                      ];

                      // custom options
                      $options = $this->getItemOptions();
                      if ($options)
                      foreach ($options as $option)
                      // draw options label
                      $lines[][] = [
                      'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
                      'font' => 'italic',
                      'feed' => 35,
                      ];

                      if ($option['value'])
                      if (isset($option['print_value']))
                      $printValue = $option['print_value'];
                      else
                      $printValue = $this->filterManager->stripTags($option['value']);

                      $values = explode(', ', $printValue);
                      foreach ($values as $value)
                      $lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];





                      $lineBlock = ['lines' => $lines, 'height' => 20];

                      $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);

                      $this->setPage($page);



                      /*
                      * Return Value of custom attribute
                      * */
                      private function getProductImage($item, &$page)

                      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                      $productId = $item->getOrderItem()->getProductId();
                      $data = $objectManager->get('MagentoCatalogModelProductRepository')->get($item->getSku());
                      $image = $data->getImage();

                      if (!is_null($image))
                      try

                      $imagePath = '/catalog/product/'.$image;

                      $filesystem = $objectManager->get('MagentoFrameworkFilesystem');
                      $media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);

                      if ($media_dir->isFile($imagePath))
                      return $media_dir->getAbsolutePath($imagePath);

                      else
                      return null;

                      catch (Exception $e)
                      return false;







                      Here's simple product's image in Invoice based of variant selection of
                      configure product.




                      enter image description here



                      More References



                      Reference 1 , Reference 2 , Reference 3






                      share|improve this answer















                      I have override DefaultInvoice



                      class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice

                      public function draw()

                      $order = $this->getOrder();
                      $item = $this->getItem();
                      $pdf = $this->getPdf();
                      $page = $this->getPage();
                      $lines = [];


                      // draw Product image
                      $productImage = $this->getProductImage($item, $page);

                      // draw Product name
                      $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];

                      $lines[0][] = array(
                      'text' => $productImage,
                      'is_image' => 1,
                      'feed' => 200
                      );

                      // draw SKU
                      $lines[0][] = [
                      'text' => $this->string->split($this->getSku($item), 17),
                      'feed' => 370,
                      'align' => 'right',
                      ];

                      // draw QTY
                      $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];

                      // draw item Prices
                      $i = 0;
                      $prices = $this->getItemPricesForDisplay();
                      $feedPrice = 425;
                      $feedSubtotal = $feedPrice + 140;
                      foreach ($prices as $priceData)
                      if (isset($priceData['label']))
                      // draw Price label
                      $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
                      // draw Subtotal label
                      $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
                      $i++;

                      // draw Price
                      $lines[$i][] = [
                      'text' => $priceData['price'],
                      'feed' => $feedPrice,
                      'font' => 'bold',
                      'align' => 'right',
                      ];
                      // draw Subtotal
                      $lines[$i][] = [
                      'text' => $priceData['subtotal'],
                      'feed' => $feedSubtotal,
                      'font' => 'bold',
                      'align' => 'right',
                      ];
                      $i++;


                      // draw Tax
                      $lines[0][] = [
                      'text' => $order->formatPriceTxt($item->getTaxAmount()),
                      'feed' => 515,
                      'font' => 'bold',
                      'align' => 'right',
                      ];

                      // custom options
                      $options = $this->getItemOptions();
                      if ($options)
                      foreach ($options as $option)
                      // draw options label
                      $lines[][] = [
                      'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
                      'font' => 'italic',
                      'feed' => 35,
                      ];

                      if ($option['value'])
                      if (isset($option['print_value']))
                      $printValue = $option['print_value'];
                      else
                      $printValue = $this->filterManager->stripTags($option['value']);

                      $values = explode(', ', $printValue);
                      foreach ($values as $value)
                      $lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];





                      $lineBlock = ['lines' => $lines, 'height' => 20];

                      $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);

                      $this->setPage($page);



                      /*
                      * Return Value of custom attribute
                      * */
                      private function getProductImage($item, &$page)

                      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                      $productId = $item->getOrderItem()->getProductId();
                      $image = $objectManager->get('MagentoCatalogModelProduct')->load($productId);

                      if (!is_null($image))
                      try

                      $imagePath = '/catalog/product/'.$image->getSmallImage();

                      $filesystem = $objectManager->get('MagentoFrameworkFilesystem');
                      $media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);

                      if ($media_dir->isFile($imagePath))
                      return $media_dir->getAbsolutePath($imagePath);

                      else
                      return null;

                      catch (Exception $e)
                      return false;







                      Which returns me PDF like this. (working on Image rotation :) )




                      enter image description here



                      UPDATED




                      For variant based product - based on configure product's attribute
                      selection




                      class DefaultInvoice extends MagentoSalesModelOrderPdfItemsInvoiceDefaultInvoice

                      public function draw()

                      $order = $this->getOrder();
                      $item = $this->getItem();
                      $pdf = $this->getPdf();
                      $page = $this->getPage();
                      $lines = [];


                      // draw Product image
                      $productImage = $this->getProductImage($item, $page);

                      // draw Product name
                      $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];

                      $lines[0][] = array(
                      'text' => $productImage,
                      'is_image' => 1,
                      'feed' => 200
                      );

                      // draw SKU
                      $lines[0][] = [
                      'text' => $this->string->split($this->getSku($item), 17),
                      'feed' => 370,
                      'align' => 'right',
                      ];

                      // draw QTY
                      $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 475, 'align' => 'right'];

                      // draw item Prices
                      $i = 0;
                      $prices = $this->getItemPricesForDisplay();
                      $feedPrice = 425;
                      $feedSubtotal = $feedPrice + 140;
                      foreach ($prices as $priceData)
                      if (isset($priceData['label']))
                      // draw Price label
                      $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
                      // draw Subtotal label
                      $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
                      $i++;

                      // draw Price
                      $lines[$i][] = [
                      'text' => $priceData['price'],
                      'feed' => $feedPrice,
                      'font' => 'bold',
                      'align' => 'right',
                      ];
                      // draw Subtotal
                      $lines[$i][] = [
                      'text' => $priceData['subtotal'],
                      'feed' => $feedSubtotal,
                      'font' => 'bold',
                      'align' => 'right',
                      ];
                      $i++;


                      // draw Tax
                      $lines[0][] = [
                      'text' => $order->formatPriceTxt($item->getTaxAmount()),
                      'feed' => 515,
                      'font' => 'bold',
                      'align' => 'right',
                      ];

                      // custom options
                      $options = $this->getItemOptions();
                      if ($options)
                      foreach ($options as $option)
                      // draw options label
                      $lines[][] = [
                      'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
                      'font' => 'italic',
                      'feed' => 35,
                      ];

                      if ($option['value'])
                      if (isset($option['print_value']))
                      $printValue = $option['print_value'];
                      else
                      $printValue = $this->filterManager->stripTags($option['value']);

                      $values = explode(', ', $printValue);
                      foreach ($values as $value)
                      $lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];





                      $lineBlock = ['lines' => $lines, 'height' => 20];

                      $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true],1);

                      $this->setPage($page);



                      /*
                      * Return Value of custom attribute
                      * */
                      private function getProductImage($item, &$page)

                      $objectManager = MagentoFrameworkAppObjectManager::getInstance();
                      $productId = $item->getOrderItem()->getProductId();
                      $data = $objectManager->get('MagentoCatalogModelProductRepository')->get($item->getSku());
                      $image = $data->getImage();

                      if (!is_null($image))
                      try

                      $imagePath = '/catalog/product/'.$image;

                      $filesystem = $objectManager->get('MagentoFrameworkFilesystem');
                      $media_dir = $filesystem->getDirectoryRead(MagentoFrameworkAppFilesystemDirectoryList::MEDIA);

                      if ($media_dir->isFile($imagePath))
                      return $media_dir->getAbsolutePath($imagePath);

                      else
                      return null;

                      catch (Exception $e)
                      return false;







                      Here's simple product's image in Invoice based of variant selection of
                      configure product.




                      enter image description here



                      More References



                      Reference 1 , Reference 2 , Reference 3







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Apr 18 at 11:10

























                      answered Apr 18 at 8:14









                      AadityaAaditya

                      4,45621139




                      4,45621139





















                          0














                          You can replace following line in your code



                          $product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);


                          With following line



                          $product = $objectManagerHere->get('MagentoCatalogModelProductRepository')->get($_item->getSku());


                          With this, you can get appropriate simple product of configurable product.






                          share|improve this answer



























                            0














                            You can replace following line in your code



                            $product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);


                            With following line



                            $product = $objectManagerHere->get('MagentoCatalogModelProductRepository')->get($_item->getSku());


                            With this, you can get appropriate simple product of configurable product.






                            share|improve this answer

























                              0












                              0








                              0







                              You can replace following line in your code



                              $product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);


                              With following line



                              $product = $objectManagerHere->get('MagentoCatalogModelProductRepository')->get($_item->getSku());


                              With this, you can get appropriate simple product of configurable product.






                              share|improve this answer













                              You can replace following line in your code



                              $product = $objectManagerHere->get('MagentoCatalogModelProduct')->load($productId);


                              With following line



                              $product = $objectManagerHere->get('MagentoCatalogModelProductRepository')->get($_item->getSku());


                              With this, you can get appropriate simple product of configurable product.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Apr 18 at 5:00









                              Yash ShahYash Shah

                              93628




                              93628





















                                  0














                                  I think you should try with cart_page_product_thumbnail instead of product_thumbnail_image in your get product image code.



                                  Your code should be like this.



                                  $image_url = $imageHelper->init($product, 'cart_page_product_thumbnail')->setImageFile($product->getFile())->resize(80, 80)->getUrl();


                                  I have used the above code to display product image in the Email template and it is working fine with configurable products. and I think it also works for the invoice email template.



                                  I have also seen so many users use cart_page_product_thumbnail please check below reference link.



                                  • Product image in-new order email

                                  • Display product image in sales order view-page

                                  I hope it helps!






                                  share|improve this answer



























                                    0














                                    I think you should try with cart_page_product_thumbnail instead of product_thumbnail_image in your get product image code.



                                    Your code should be like this.



                                    $image_url = $imageHelper->init($product, 'cart_page_product_thumbnail')->setImageFile($product->getFile())->resize(80, 80)->getUrl();


                                    I have used the above code to display product image in the Email template and it is working fine with configurable products. and I think it also works for the invoice email template.



                                    I have also seen so many users use cart_page_product_thumbnail please check below reference link.



                                    • Product image in-new order email

                                    • Display product image in sales order view-page

                                    I hope it helps!






                                    share|improve this answer

























                                      0












                                      0








                                      0







                                      I think you should try with cart_page_product_thumbnail instead of product_thumbnail_image in your get product image code.



                                      Your code should be like this.



                                      $image_url = $imageHelper->init($product, 'cart_page_product_thumbnail')->setImageFile($product->getFile())->resize(80, 80)->getUrl();


                                      I have used the above code to display product image in the Email template and it is working fine with configurable products. and I think it also works for the invoice email template.



                                      I have also seen so many users use cart_page_product_thumbnail please check below reference link.



                                      • Product image in-new order email

                                      • Display product image in sales order view-page

                                      I hope it helps!






                                      share|improve this answer













                                      I think you should try with cart_page_product_thumbnail instead of product_thumbnail_image in your get product image code.



                                      Your code should be like this.



                                      $image_url = $imageHelper->init($product, 'cart_page_product_thumbnail')->setImageFile($product->getFile())->resize(80, 80)->getUrl();


                                      I have used the above code to display product image in the Email template and it is working fine with configurable products. and I think it also works for the invoice email template.



                                      I have also seen so many users use cart_page_product_thumbnail please check below reference link.



                                      • Product image in-new order email

                                      • Display product image in sales order view-page

                                      I hope it helps!







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Apr 18 at 7:10









                                      Chirag PatelChirag Patel

                                      2,648423




                                      2,648423



























                                          draft saved

                                          draft discarded
















































                                          Thanks for contributing an answer to Magento Stack Exchange!


                                          • Please be sure to answer the question. Provide details and share your research!

                                          But avoid


                                          • Asking for help, clarification, or responding to other answers.

                                          • Making statements based on opinion; back them up with references or personal experience.

                                          To learn more, see our tips on writing great answers.




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f266775%2fproduct-image-in-invoice-email-template%23new-answer', 'question_page');

                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Identifying “long and narrow” polygons in with PostGISlength and width of polygonWhy postgis st_overlaps reports Qgis' “avoid intersections” generated polygon as overlapping with others?Adjusting polygons to boundary and filling holesDrawing polygons with fixed area?How to remove spikes in Polygons with PostGISDeleting sliver polygons after difference operation in QGIS?Snapping boundaries in PostGISSplit polygon into parts adding attributes based on underlying polygon in QGISSplitting overlap between polygons and assign to nearest polygon using PostGIS?Expanding polygons and clipping at midpoint?Removing Intersection of Buffers in Same Layers

                                          Masuk log Menu navigasi

                                          อาณาจักร (ชีววิทยา) ดูเพิ่ม อ้างอิง รายการเลือกการนำทาง10.1086/39456810.5962/bhl.title.447410.1126/science.163.3863.150576276010.1007/BF01796092408502"Phylogenetic structure of the prokaryotic domain: the primary kingdoms"10.1073/pnas.74.11.5088432104270744"Towards a natural system of organisms: proposal for the domains Archaea, Bacteria, and Eucarya"1990PNAS...87.4576W10.1073/pnas.87.12.4576541592112744PubMedJump the queueexpand by handPubMedJump the queueexpand by handPubMedJump the queueexpand by hand"A revised six-kingdom system of life"10.1111/j.1469-185X.1998.tb00030.x9809012"Only six kingdoms of life"10.1098/rspb.2004.2705169172415306349"Kingdoms Protozoa and Chromista and the eozoan root of the eukaryotic tree"10.1098/rsbl.2009.0948288006020031978เพิ่มข้อมูล