Magento® Add Order Total in Invoice PDF

Sometimes you need to add custom order totals to your Magento store. For exmple you may have added new attribute ‘total_surcharge‘ as custom order total attribute. This new order total will be visible in admin sales order view and invoice view generally. But when you generate the PDF from invoice, the new order total is not visible there.
We need to perform following simple steps in our module to add order total in invoice PDF:

1. Open your modules config.xml and add following lines under global node:


        <!-- Add new order totals in invoice PDF in admin -->
                <total_surcharge translate ="title">
                    <title>Assistance Fee</title>
                    <source_field>total_surcharge</source_field> <!-- Source field is the code of your custom total attribute -->
                    <model>shipmeorders/sales_pdf_assistancefee</model> <!-- This is the new model that we will create -->
                    <amount_prefix>-</amount_prefix> <!-- If you need to place any sign before total -->


2. Create the new model for showing the new total in PDF:

// app/code/local/Company/Mytotal/Model/Sales/Pdf/Surcharge.php

class Company_Mytotal_Model_Sales_Pdf_Surcharge extends Mage_Sales_Model_Order_Pdf_Total_Default
    public function getTotalsForDisplay()
        // getAmount will automatically get the value of your new total
        // its value id defined source_field in your config.xml
        $amount = $this->getAmount();
        $label = Mage::helper('mytotal')->__('Surchage').':';        
        $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
        $total = array(
            'amount'    => Mage::helper('core')->currency($amount, true, false),
            'label'     => $label,
            'font_size' => $fontSize
        return array($total);

Now try to print invoice in admin, you should see the new order total there.

Written by Arvind Bhardwaj

Arvind is a certified Magento 2 expert with more than 10 years of industry-wide experience.


5 thoughts on “Magento® Add Order Total in Invoice PDF

  1. Hi Arvind
    i am absolutely stuck with this problem:

    I get no totals on the emailed invoice PDF. It is driving me grazy. There are totals on every needed place in the admin but not on the PDf that is send. What am i doing wrong. I checked every setting in admin, changed language, set back the mage version to and back (its 1.9.3 again now) but no effort at all..

    So before i jump from a bridge…. help!

    Kind regards

  2. How can we implement same technique to print bar code for any given reference number in shipping label?

Comments are closed.