Edit the Magento Invoice PDF Templates

Code Location

  • /app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php
  • /app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php

Changing the font size

Change the font size in the two files:

  • /app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php (line 487-507)
  • /app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php (line 255-274)

Change the invoice logo

  • Admin -> Configuration -> Sales -> Invoice and Packing Slip Design

More info

  • Changing the invoice size from A4 to letter
  • Changing the font from Libertine to Helvetica
  • Read up here.

Leave a Reply

44 Comments

  1. Matt

    How do I change the line spacing for the address and the size of the logo? Also for some reason the Grand Total and the product line font size still stays at 7pts.
    thanks for any help!

  2. Is it possible to generate invoice pdf without zlib extension?
    I tried to comment out logo and some other stuff but nothing changes, i receive an error from Zend Framework pdf code: “You have to use zlib extension”

  3. Arno Smit

    How would i go about adding something like the customers tax/vat number on the invoice?

  4. You can get customer TAX/VAT value like that:

    $customer = Mage::getModel(‘customer/customer’)->load($order->getData(‘customer_id’));
    $taxVat = $customer->getData(‘taxvat’);

    Then you can write it into right place in pdf document like that:

    $page->drawText($taxVat);

  5. R3Nd3r

    but aren’t those templates gone with the next update?

    is there a way to put them inside the template folder itself ?

  6. m4t

    This:

    $customer = Mage::getModel(’customer/customer’)->load($order->getData(’customer_id’));
    $taxVat = $customer->getData(’taxvat’);

    works only for registered user. How can I get tax/vat number for guest customer?

  7. Ragento

    How would i go about adding a attribute like ‘manufacturer’ on the invoice?

  8. pdf invoice

    how do you switch shipping costs with total tax, now shipping costs is displayed below total tax, i want to switch these two in the pdf layout, because now it is confusing. In checkout page it’s all shown ok, but not in the invoice screen in backend and also in the pdf printout the shipping costs and tax are switched… How to resolve this?

  9. Sim

    How would one go about getting the invoiced date so i can add to the invoice. It is a requirments by law in Australia for the invocied date to be present on our tax invoices or else it is an illegal invoice. There are other requirments that i needed to address, but have managed to get them all sorted, just missing the invoiced date.

  10. Before making any changes to the template files be sure to copy them into

    » /app/code/local/Mage/Sales/Model/Order/Pdf/…..etc

    That way they won’t be overwritten when you upgrade. Never change anything in app/code/core or you will be in a big mess when it comes to upgrades.

  11. Still trying to change the font size below the QTY Products SKU area.
    i changed the abstract.php in the items folder but i get no changes.

  12. Thanks for the helpful advice. Our lure store customers will appreciate the Barracuda logo on our invoice

  13. Could anyone shed any light on increasing the line-height? I have managed to increase the font-size but can’t seem to find the right var for the line-height?

  14. Jonathan

    Very helpfull for VAT 😉

    TY

  15. I have just stumbled on a similar problem to Ken’s. May be too late to help you Ken (sorry) but for anyone else struggling with how to change the font size for Subtotal, Tax, S&H and Grand total:
    In
    appcodecoreMageSalesModelOrderPdfAbstract.php,
    change
    $fontSize = (isset($total[‘font_size’]) ? $total[‘font_size’] : 7);
    to
    $fontSize = (your desired size in points); (line 406 in Magento 1.3.2).
    Will not work by simply changing the size in the existing line as this line tells Magento to use the size indicated ONLY IF $total[‘font_size’] has not been previously set (could not find where this gets set). Note: I have not viewed all pdfs generated by Magento to see what effect this had but it did resolve the font size problem as described by Ken on 8 Mar 2010. Hope this helps others.

  16. Martin

    So do I understand this correctly that I have to edit PHP code to change the template? I need a completely different layout and it sounds like a lot of hassle to do all that in PHP.

  17. Igor

    Anyone has a solution for that request??

    “how do you switch shipping costs with total tax, now shipping costs is displayed below total tax, i want to switch these two in the pdf layout, because now it is confusing. In checkout page it’s all shown ok, but not in the invoice screen in backend and also in the pdf printout the shipping costs and tax are switched… How to resolve this? “

  18. Heinz

    how can I insert in the bill payment information? E.g. Payment: PayPal.
    Thank you!

  19. Hey, to show TAX/VAT in PDF you only have to print something like that:
    $taxvat = $this->getData(‘customer_taxvat’);
    $page->drawText(‘TAX/VAT: ‘.$taxvat, 100, 100);

    remeber to change you x and y values :-]

  20. I’m sorry but I made mistake
    $taxvat = $order->getData(‘customer_taxvat’);

  21. how can i add a customers phone number to my invoice. I also plan to redesign the entire invoice template, what would be a good reference to get me started.

  22. How about line height? if i use font-size 9, the two lines of words will overlap each other..

  23. Thankyou, just what I needed! I’ve been searching for the right file to edit for ages. I’ve managed to change the font, and lodo layout without any problems. However, in the Shipping Method box it insists on showing the shipping cost ex VAT, is there any way to change this?

  24. Is there anyway to alter the position of the address? As we use packet labels like Amazon.

  25. thank for the pointers, but editing this pdf invoice is an absolute horror 🙂

  26. A bit old post, but magento pdf are hard so hope I can help.
    Regarding line height as some has asked: find the places in the code saying $this->y -=XX; (most xx=10) change all these places to a higher number if you change the fontsize.

    Also I just want to promote our new extension, where you can change the complete layout of all the pdf’s. All done from a WYSIWYG editor.
    Check it out at ext4mage.com

  27. This info may be too late to help the folks who’ve already been here but may help those yet to come 🙂 Took me hours to figure this out.

    For whatever reason, the code to change the font size in the ‘Sub-Totals’ area is in the file /app/code/core/Mage/Sales/etc/config.xml

    Search the file for ‘font_size’ to locate the exact spot.

    Cheers…BMan

  28. Hi Igor and PDF Invoice,

    This info is a little late but…in order to switch the ‘Shipping & Handling’ position with the total ‘Tax’ position on the PDF Invoice, edit the following file:

    /app/code/core/Mage/Sales/etc/config.xml

    1. Search the file for ‘Shipping & Handling’
    2. 4 lines below that, see ‘400’
    3. Change the number (400) to any number greater than 200 but less than 300 (I’ve changed mine to 295).
    4. Save and upload the file and Voila, the sections have been switched.

    Cheers…BMan

  29. Hi Igor and PDF Invoice,

    This info is a little late but…in order to switch the ‘Shipping & Handling’ position with the total ‘Tax’ position on the PDF Invoice, edit the following file:

    /app/code/core/Mage/Sales/etc/config.xml

    1. Search the file for ‘Shipping & amp; Handling’ (remove the space after ‘&’)
    2. 4 lines below that, see ‘sort_order>400</sort_order'
    3. Change the number (400) to any number greater than 200 but less than 300 (I’ve changed mine to 295).
    4. Save and upload the file and Voila, the sections have been switched.

    Cheers…BMan

    (sorry for the re-post. some info in my first post was interpreted by html)

  30. Please how to add background image in facture pdf

    I do this but it doesn’t work

    protected function insertLogo(&$page, $store = null)
    {
    $image = Mage::getStoreConfig(‘sales/identity/logo’, $store);
    $image1 = Mage::getStoreConfig(‘sales/identity/logo’, $store);
    if ($image&&$image1) {
    $image = Mage::getStoreConfig(‘system/filesystem/media’, $store) . ‘/sales/store/logo/’ . $image;
    $image1 = Mage::getStoreConfig(‘system/filesystem/media’, $store) . ‘/sales/store/logo/’ . $image1;
    if (is_file($image) && is_file($image1)) {
    $image = Zend_Pdf_Image::imageWithPath($image);
    $image1 = Zend_Pdf_Image::imageWithPath($image1);
    //$page->drawImage($image, 35, 800, 125, 825);
    $page->drawImage($image, 60, 800, 125, 825);
    $page->drawImage($image1, 100, 600, 600, 600);
    //$page->drawImage($image, 500, -60, 600, 40);
    }
    }
    }

  31. Vinodh

    Worked Great>
    Thanks a lot.

  32. Ko

    I had made changes to /app/code/local/Mage/Sales/Model/Order/Pdf/Abstract.php about a year ago and
    it was working fine till a few days ago. Now the PDF invoices come out as they did before I made the changes.

    How can that be?

  33. RvP

    I would like to add my bank account details in the footer of the pdf invoice.

    Could some1 provide me with the code since i already allocated the correct file(s)

    Much appreciated your response

Next ArticleMy Telus Tech Support Story