How to Add Header and Footer to Magento 2 Invoice PDF

How to Add Header and Footer to Magento 2 Invoice PDF

As a Magento 2 store owner, you surely know that you always have to send invoices to your customers with every order you deliver. Sending out authoritative transactional documents is crucial for both yours and your customers’ accounting and tax objectives.

Another important thing is how is your invoice designed. Earlier, I had shown how to make changes in the default invoice with the method to override a method of abstract file of Magento 2 invoice PDF. It is necessary that you refer that post prior to implementing the below solution.

Having a well-designed invoice pays off. Today, I’ll show how to add header and footer to Magento 2 invoice PDF programmatically.  Headers and footers carry the important company information to give order documents a more professional look. Showcase your brand name and logo, add the company details and improve the brand engagement with existing customers!

A makeover for the default Magento 2 invoice PDF with informative header and footer is just going to be easy with the below solution!

Add the function _drawFooter() in the class – Vendor\Module\Model\Rewrite\Order\Pdf\Invoice

Method to Add Header and Footer to Magento 2 Invoice PDF:

In this class, you have to override insertOrder() method and replace the following code:
with:
That’s it! The above example is to add the logo and address in the footer. You can customize the code as per the business requirement and send invoices as the specimen shown here:

Header and Footer to Magento 2 Invoice PDF - Meetanshi

Feel free to ask any doubts in the Comments section below. I’d be happy to help.

I’d be very grateful if you helped share this helpful post on social media to fellow developers!

Thanks!

 

Get Weekly Updates

Never miss Magento tips, tricks, tutorials, and news.

Thank you for subscribing.

Something went wrong.

5
(based on 13 Reviews)

Sanjay is a co-founder at Meetanshi. He is a Certified Magento Developer who loves creating Magento E-commerce solutions. Owing to his contributions in Magento Forums and posting solutions, he is among the top 50 contributors of the Magento community in 2019. When he is not engrossed with anything related to Magento, he loves to play cricket.

6 comments On How to Add Header and Footer to Magento 2 Invoice PDF

  • Could not find $this->insertTotals($page, $invoice); in the class?
    Where do we need to add this.
    I have created a module also with your reference blog for the pdf invoice changes.
    but its not working as could not find “$this->insertTotals($page, $invoice);” in the class..

  • Max Pronko (@max_pronko)

    Hi Sanjay,

    What is the purpose of using Object Manager here in the code sample?

    Thanks.

    • Hello,
      The Object Manager is used to initialize Magento\Framework\Filesystem
      Using Magento\Framework\Filesystem object, we can get absolute path of current magento.
      Thanks.

Leave a reply:

Your email address will not be published.