I am using magento 2.1. I want to add some "term & condition" at the bottom of customer invoice. How can I add a Custom footer on PDF invoice that is generated in Magento2?

Can anyone explain me how to do that.


Override invoice php file for invoice pdf customization, Magento\Sales\Model\Order\Pdf\Invoice,

class Invoicepdf extends \Magento\Sales\Model\Order\Pdf\Invoice{
     public function getPdf($invoices = [])
            //custom code of getpdf

                //add new footer section this is our custom code function...

             return $pdf;

        protected function _drawFooter(\Zend_Pdf_Page $page)
            $this->y =50;    
            $page->setFillColor(new \Zend_Pdf_Color_RGB(1, 1, 1));
            $page->setLineColor(new \Zend_Pdf_Color_GrayScale(0.5));
            $page->drawRectangle(60, $this->y, 510, $this->y -30);

            $page->setFillColor(new \Zend_Pdf_Color_RGB(0.1, 0.1, 0.1));
            $page->setFont(\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA), 7);
            $this->y -=10;
            $page->drawText("Company name", 70, $this->y, 'UTF-8');
            $page->drawText("Tel: +123 456 676", 230, $this->y, 'UTF-8');
            $page->drawText("Registered in Countryname", 430, $this->y, 'UTF-8');


Page size can be retrieved from a page object's get widht and height function, using $page object:

//start with zend_pdf method of zend frameworks,

$pdf = new \Zend_Pdf();

//create new page in pdf

$page = $pdf->newPage(\Zend_Pdf_Page::SIZE_A4);

//set color

$page->setFillColor(new \Zend_Pdf_Color_RGB(0, 0, 0));

//set font

$page->setFont(\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA), 8);

//set stye for pdf,

$style = new \Zend_Pdf_Style();

//set bold font

$this->_setFontBold($style, 10);

$page->drawText($title, 225, $this->y, 'UTF-8');

//get page widht

$width  = $page->getWidth(); //width for A4 page, 595

//get page height

$height = $page->getHeight(); //Height for A4 page,842
| improve this answer | |

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.