How to Add Header And Footer to Magento 2 Invoice PDF?

How to Add Header And Footer to Magento 2 Invoice PDF?

Are you ready to enhance your business documents? Magento 2 Invoice PDF customization can make a significant difference. Adding headers and footers to your invoice PDFs has dual benefits. It boosts your brand’s visibility and provides important information in a professional layout.

This tutorial will cover how to seamlessly integrate customized headers and footers into your Magento 2 invoice PDFs.

Key Takeaways

  • Learn how to customize Magento 2 invoice PDFs with headers and footers.

  • Enhance your brand's visibility and professionalism with customized invoice layouts.

  • Gain step-by-step guidance on integrating headers and footers into invoice PDFs.

  • Tailor the customization to meet your specific business requirements.

  • Ensure a seamless and professional invoicing experience for your clients.

  • Maximize the impact of your invoices with personalized branding elements.

What is Magento 2 Invoice PDF?

Understanding Magento 2 Invoice PDF

Magento 2 Invoice PDF is a feature that allows you to generate and customize PDF invoices for orders placed in your Magento 2 store.

PDF invoicing functionality is built into the Magento 2 platform, but it can also be enhanced through the use of third-party extensions.

The default Magento 2 invoice PDF template includes basic information such as:

  • Order details

  • Product details

  • Customer information

You can customize the invoice design to match your brand better or include additional information. When customizing the invoice PDF, you can change elements such as:

  • Layout

  • Fonts

  • Colors

  • Logos

You can also add additional information, such as:

Extension Feature Description
PDF document generation Some extensions allow you to generate other PDF documents. You can customize these, such as credit memos and shipping labels. You can create different templates for each type of document.
PDF invoice attachment A useful feature offered by some extensions is the ability to attach PDF invoices to order confirmation emails. It provides customers with a convenient way to access their invoices. They can do so without having to log into their account on your website.

Steps to Add Header and Footer to Magento 2 Invoice PDF

Step 1: Create a custom module

  • Create a new module directory in the app/code directory of your Magento 2 installation.

  • Create the necessary module files, including registration.php, module.xml, and composer.json.

  • In the etc/module.xml file, specify the module name and dependencies.

Step 2: Create a plugin for the invoice PDF model

  • In your module's etc/di.xml file, add a plugin for the Magento\Sales\Model\Order\Pdf\Invoice class.

  • Specify the plugin class that will be responsible for modifying the invoice PDF.

Step 3: Create the plugin class

  • Create a new PHP class in your module's Plugin directory.

  • Make sure the class implements the afterGetPdf method, which will be called after the original getPdf method of the invoice PDF model.

Step 4: Modify the invoice PDF

  • In the afterGetPdf method, get the PDF object using $result->render().

  • Create a new instance of Zend_Pdf_Page to add as a new page to the PDF.

  • Set the font and font size for the header and footer using $page->setFont().

  • Add the header content to the page using $page->drawText(), specifying the text, coordinates, and encoding.

  • Add the footer content to the page using $page->drawText(), specifying the text, coordinates, and encoding.

  • Add the new page to the existing PDF using $pdf->pages[] = $page.

  • Return the modified PDF object.

Step 5: Add configuration options (optional)

  • If you want to make the header and footer content configurable, create a new configuration file in the etc directory of your module.

  • Define configuration fields for the header and footer content, such as text, font size, and color.

  • Use the Magento\Framework\App\Config\ScopeConfigInterface to retrieve the configuration values in your plugin class.

Step 6: Test the Customization

Testing the Customization

  • Clear the Magento cache and regenerate static files.

  • Place a new order and generate an invoice.

  • Check the generated invoice PDF to verify that the header and footer are added correctly.

Here's an example of how the afterGetPdf method in your plugin class might look:

public function afterGetPdf(\Magento\Sales\Model\Order\Pdf\Invoice $subject, $result)
    $pdf = $result->render();
    $page = new \Zend_Pdf_Page(\Zend_Pdf_Page::SIZE_A4);
    $font = \Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA);
     // Add header content
    $page->setFont($font, 12);
    $page->drawText('Header Content', 50, 800, 'UTF-8');
        // Add footer content
    $page->setFont($font, 10);
    $page->drawText('Footer Content', 50, 50, 'UTF-8');
        $pdf->pages[] = $page;
    return $pdf;

Note: Remember to replace the placeholders in the code with your actual header and footer content and adjust the coordinates as needed.

Benefits of Magento 2 Invoice PDF For Your Store

1. Customization

Benefits of Magento 2 Invoice PDF: Customization

  • Ability to customize the invoice template according to business requirements.

  • Add elements such as:

    1. Company logo

    2. Custom texts

    3. Additional images

  • Highly flexible template editor with drag-and-drop functionality.

2. Comprehensive Document Generation

  • Generate various PDF documents, including:

    1. Invoices

    2. Order PDFs

    3. Shipment labels

    4. Credit memos

  • Manage all essential PDF documents within a single extension.

3. Brand Consistency

Benefits of Magento 2 Invoice PDF: Brand Consistency

  • Replace the default Magento invoice with your custom-designed template.

  • Maintain a consistent brand identity across all customer touchpoints.

4. Customer Convenience

  • Allow customers to download invoices directly from the store's frontend.

  • Access invoices from the customer account area.

  • Eliminates the need for manual requests and saves time.

5. Automated Document Attachment

Benefits of Magento 2 Invoice PDF: Automated Document Attachment

  • Attach PDF documents to transactional emails.

  • Automatically send invoices, shipment labels, and other relevant documents along with:

    1. Order confirmation emails

    2. Shipping notification emails

6. Flexibility for Developers

  • Create custom templates using HTML and CSS.

  • Full control over the layout and styling of invoices.

  • Ensure alignment with brand guidelines.

Use Case of Magento 2 PDF Invoice

Use Case Goal Challenge Solution
Generating Professional Invoices Enhance the professionalism of your business by providing well-designed PDF billing documents for orders and transactions. Default Magento 2 allows you to create invoices. However, it needs more extensive customization and branding options. - Automatically generate a customized PDF invoice for each transaction.
- Attach the branded invoice to the confirmation email sent to customers after an order is placed and paid.
- Incorporate your store's logo, address, and QR codes or barcodes. It helps streamline management and maintain a consistent brand identity.
Enabling Easy Download and Print Options Offer a convenient way for customers and administrators to download and print invoice documents. The default Magento system does not include a print feature for PDF files. - Make PDF documents easily downloadable and printable for both customers and administrators.
- Provide the flexibility to display or hide the print option based on your business strategy.
- Allow configuration of different paper sizes for printing to accommodate various preferences.
Versatile PDF Document Templates Generate PDF documents for various purposes beyond just invoices. Default Magento 2 does not support creating PDF files for transactions other than purchases. - Offer a collection of 12 pre-designed templates for different document types.
- Utilize PDF downloadable files for a range of scenarios, such as orders, shipping, refunds, and more.
- Empower businesses to customize company information, style, colors, and other elements within the documents.


1. What is Magento 2 Invoice PDF customization?

Magento 2 Invoice PDF customization enables you to modify the appearance and content of your invoice PDF templates. This customization is tailored to meet your specific needs.

2. How can I change the default invoice PDF template in Magento 2?

You can change the default invoice PDF template in Magento 2 by using a template customization extension. Alternatively, you can edit the code of the existing template manually.

3. Can the invoice PDF be customized in Magento 2 with an open-source extension?

Yes, there are open-source invoice extension modules available for Magento 2. These modules enable you to customize your invoice PDF templates.

4. What are the benefits of customizing the Magento 2 PDF invoice?

Customizing the Magento 2 PDF invoice allows you to tailor the design, layout, and content of your invoices. This customization ensures that your invoices match your brand identity and provide a personalized experience for your customers.

5. How can I add a new template to my Magento 2 PDF invoice extension?

A: You can add a new template to your Magento 2 PDF invoice extension by creating a custom template file and configuring the extension to use it.

6. Is there a module available for Magento that enables the generation of custom PDF documents for orders?

Yes, there are Magento modules available. They provide the ability to generate custom PDF documents for orders. These documents include invoices and credit memos.

7. Can I download the customized PDF invoices from the customer area in Magento 2?

Yes, you can download the customized PDF invoices from the customer area in Magento 2 if the extension you are using provides this feature.



Magento 2 PDF Invoice can significantly improve the overall customer experience. It can strengthen brand perception and optimize document management processes. Here's a recap of what you've learned in our comprehensive guide:

  • Steps to add headers and footers to Magento 2 invoice PDFs.

  • Elevate your brand's visibility and professionalism with personalized invoice layouts.

  • Explore the advantages of Magento 2 Invoice PDF customization. These include compatibility, flexibility, and brand consistency.

  • Discover how tailored PDF invoices can refine management and enhance brand identity.

Explore managed Magento hosting options to improve performance and utilize magento invoicing pdf.

Andrea Oriane
Andrea Oriane
Technical Writer

Andrea specializes in creating informative content for Magento. With extensive e-commerce knowledge and understanding of Magento functionalities, she crafts articles for a wide range of audience.

Get the fastest Magento Hosting! Get Started