I need to add a line between items in Magento2 email Invoice template. I have referred below link for Magento1. How can I achieve same for Magento2

PDF Invoice draw line between items


1 Answer 1


In di.xml override the file vendor\magento\module-sales\Model\Order\Pdf\Invoice.php

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="Magento\Sales\Model\Order\Pdf\Invoice" type="Vendor\Module\Model\Order\Pdf\Invoice" />

Copy function getPdf in your new file

namespace Vendor\Module\Model\Order\Pdf;

class Invoice extends \Magento\Sales\Model\Order\Pdf\Invoice
    public function getPdf($invoices = [])
        //Old function code here

find the line $this->_drawItem($item, $page, $order);
After this you can add your code to draw the line:

$page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
$page->drawLine(25, $this->y+12.5, 570, $this->y+12.5);

I haven't tested this, but this should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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