Call-back icon  Enterprise Sales: +1.310.775.2674 (N. America)   +44 20.3286.4137 (UK)

Magento

eCommerce Software for Online Growth

Edit an invoice PDF

Last modified by Unirgy on Sun, January 4, 2009 18:55
Source|Old Revisions  

I need to modify an invoice so I thought I would document my progress. This based on the invoice in Magento 1.1.2. If you find errors please feel free to correct them. :)

Changes will be lost every time you upgrade: The /app/code/core/Mage/Sales/Model/Order/Pdf/ folder (with these changes) will be overwritten every time you upgrade. If anyone knows how to make these changes using an override directory please share.

SIMPLEST SOLUTION: Make a copy of this file into /app/code/local/Mage/Sales/Model/Order/Pdf/ - this file will override the original, and will not be overwritten during upgrade. The drawback is that you’ll have to make sure to apply upgrade changes of the original file to this one, to avoid incompatibility with upgraded code.

The PDF is generated using the Zend_Pdf component of the Zend Framework. Here is a little tutorial

Page format: The default invoice PDF is set up in the A4 format. To set it for letter

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

change

$page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);

to

$page = $pdf->newPage(Zend_Pdf_Page::SIZE_LETTER);

Move Logo: When I changed the page format to Letter it moved the logo off the top. In ZEND_PDF the measurements are in Points(1/72 of an inch) and the origin is is lower left. I moved it down 50pt by subtracting 50 from the Y coordinates.

in /app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php find the function insertLogo and change

$page->drawImage($image, 25, 800, 125, 825);

to

$page->drawImage($image, 25, 750, 125, 775);

At this point the logo under a grey box. :)

You now need to take 50px away from the rest of the elements Y coords to move everything else down. It get’s a little messy, just keep generating PDFs to watch your progress.

most of the coords are in /app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php and in /app/code/core/Mage/Sales/Model/Order/Pdf/Invoice.php

Increase the lower Margin: We need some room at the bottom each page for some preprinted material that will be on each invoice.

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

change

if ($this->y<15) {

to

if ($this->y<215) {

This adds 200 points (about 2.75”) to the margin

Fonts: The the invoice uses Libertine. It’s a great font but with it the file size was 1.4MB without 8KB.

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

I changed all the references to Libertine to Helvetica with cut and paste.

In /app/code/core/Mage/Sales/Model/Order/Pdf/Items/Abstract.php I changed

    protected function _setFontRegular($size = 7)
    {
        $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertineC_Re-2.8.0.ttf');
        $this->getPage()->setFont($font, $size);
        return $font;
    }

    protected function _setFontBold($size = 7)
    {
        $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_Bd-2.8.1.ttf');
        $this->getPage()->setFont($font, $size);
        return $font;
    }

    protected function _setFontItalic($size = 7)
    {
        $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_It-2.8.2.ttf');
        $this->getPage()->setFont($font, $size);
        return $font;
    }

to

   protected function _setFontRegular($size = 7)
    {
        $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
        $this->getPage()->setFont($font, $size);
        return $font;
    }

    protected function _setFontBold($size = 7)
    {
        $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD);
        $this->getPage()->setFont($font, $size);
        return $font;
    }

    protected function _setFontItalic($size = 7)
    {
        $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD_ITALIC);
        $this->getPage()->setFont($font, $size);
        return $font;
    }

Also in /app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php change

$font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir()."/lib/LinLibertineFont/LinLibertineC_Re-2.8.0.ttf");

to

$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);




 

Magento User Guide

Magento Enterprise Available now

Professional Services from the Magento Team

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs
© Copyright 2009 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
108651 users|318 users currently online|199715 forum posts