Magento custom PDF invoice

Magento custom PDF invoice

August 9, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento custom PDF invoice

Customizing Magento PDF Invoices: Displaying Grand Total Price

Are you looking to customize your Magento PDF invoices for delivery purposes? If so, you might be facing challenges in displaying the grand total price on these invoices. This article will guide you through the process of retrieving and displaying the grand total price on your custom PDF invoice.

Understanding the Magento PDF Invoice Structure

Before we dive into the code, let’s understand how Magento structures its default PDF invoices. The Mage_Sales_Model_Order_Pdf_Items class is responsible for generating the items table in the PDF invoice. However, it does not directly provide access to the grand total price.

Retrieving the Grand Total Price

To get the grand total price, we need to interact with the Magento_Sales_Model_Order_Total_Abstract and Magento_Sales_Model_Quote_Total_Abstract classes. These classes handle the calculation of total amounts in Magento.

Here’s a code snippet that retrieves the grand total amount from an order object:

$order = Mage::getModel('sales/order')->loadByIncrementId($increment_id);

$totalAmount = $order->getGrandTotal();

Replace $increment_id with your actual order ID or increment ID.

Customizing the PDF Invoice

To customize the PDF invoice, you need to override the Mage_Sales_Model_Order_Pdf_Invoices class. This class extends the Zend_Pdf library and is responsible for generating the entire PDF content.

First, create a new module in your Magento installation with a custom PDF invoice model:

// app/code/local/YourCompany/MagentoPdfInvoice/etc/config.xml

<config>
    <modules>
        <YourCompany_MagentoPdfInvoice>
            <version>1.0.0</version>
        </YourCompany_MagentoPdfInvoice>
    </modules>
</config>

Then, override the Mage_Sales_Model_Order_Pdf_Invoices class in your module:

// app/code/local/YourCompany/MagentoPdfInvoice/Model/Order/Pdf/Invoices.php

class YourCompany_MagentoPdfInvoice_Model_Order_Pdf_Invoices extends Mage_Sales_Model_Order_Pdf_Invoices {
    // Your custom logic here
}

Inside the YourCompany_MagentoPdfInvoice_Model_Order_Pdf_Invoices class, you can override the _drawHeader() method to add a new line for the grand total:

protected function _drawHeader()
{
    parent::_drawHeader();

    $this->setFontBold(true);
    $this->drawText('Grand Total:', 30, $this->y - 25, 'UTF-8');
    $this->drawText($totalAmount, 280, $this->y - 25, 'UTF-8');

    // Adjust the y-coordinate
    $this->y -= 15;
}

Conclusion

Customizing Magento PDF invoices for delivery purposes involves a combination of retrieving data from order objects and overriding core models. By following this guide, you can successfully display the grand total price on your custom PDF invoices.

Remember to test your changes thoroughly before deploying them in a production environment. If you need further assistance with Magento development or any other technical challenges, feel free to reach out to our team at Laravel Company.

Happy coding!

Database Extensions Orders Pricing

Our network