3

When I click to print an invoice in my magento admin panel, it downloads a file between 900K and 1.3MB (the variation seems random, I can't see a reason for it). This is a very simple Invoice with maybe 1 - 6 line items on it, so nothing that should make it take up more than 100K or so maximum.

Is there embedded fonts?

Could it be something on the serverside?

Is there a simple tweak I can make to reduce it?

I know with modern broadband etc it doesn't really matter, but it just seems a bit unnecessary.

3 Answers 3

8

Indeed the embedded fonts are responsible for the file size.

If you replace the font with a built in one, the file size for a simple invoice goes down to about 4kb.

To do that, it becomes a bit messy. You need to rewrite the classes extending from Mage_Sales_Model_Order_Pdf_Abstract and Mage_Sales_Model_Order_Pdf_Items_Abstract

Then, replace all calls to

$font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_Re-4.4.1.ttf');

with

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

The built-in fonts you can choose from are:

Zend_Pdf_Font::FONT_COURIER
Zend_Pdf_Font::FONT_COURIER_BOLD
Zend_Pdf_Font::FONT_COURIER_OBLIQUE
Zend_Pdf_Font::FONT_COURIER_ITALIC
Zend_Pdf_Font::FONT_COURIER_BOLD_OBLIQUE
Zend_Pdf_Font::FONT_COURIER_BOLD_ITALIC
Zend_Pdf_Font::FONT_HELVETICA
Zend_Pdf_Font::FONT_HELVETICA_BOLD
Zend_Pdf_Font::FONT_HELVETICA_OBLIQUE
Zend_Pdf_Font::FONT_HELVETICA_ITALIC
Zend_Pdf_Font::FONT_HELVETICA_BOLD_OBLIQUE
Zend_Pdf_Font::FONT_HELVETICA_BOLD_ITALIC
Zend_Pdf_Font::FONT_SYMBOL
Zend_Pdf_Font::FONT_TIMES_ROMAN (or Zend_Pdf_Font::FONT_TIMES)
Zend_Pdf_Font::FONT_ZAPFDINGBATS

There are plenty of extensions that do that for you, for example https://github.com/firegento/firegento-pdf (also on Magento Connect) uses the built in FONT_HELVETICA.
The Firegento_Pdf extension makes customizing with the PDF's more pleasent in more then that regard by the way (plus, the default PDF's look nicer already).

1
  • Although this works on my magento 1.9.3 as described, it does not print "₹" in my invoices. Any suggestions?
    – Aakash
    Commented Jul 20, 2017 at 4:10
4

This is one of those shake-fists-at-the-sky-and-yell-"MAGENTO!" moments. It's because of that ******* LinLibertine font which gets imbedded. See:

Changing this font is, IMO, one of the rare justifiable use cases of local code pool overrides of core classes. I prefer that approach to a "proper" rewrite of each and every sales PDF class just for the purpose of resetting the font, as it violates DRY.

3
  • 3
    I think Magento chose LinLibertine because it supports a wider range of unicode characters than the built-in fonts (plus it has a liberal license). If you end up with ? instead of expected characters you would need to chose a font which supports your locale. Commented Jun 17, 2013 at 11:58
  • That's great info, @Fooman. It's the first time in 5 years I've heard a justification for the use of the font.
    – benmarks
    Commented Jun 17, 2013 at 12:51
  • You'd think someone might add a checkbox - use LinLibertine or use Times New Roman! Thanks for the info.
    – Toby Allen
    Commented Jun 17, 2013 at 16:01
1

It's Working for me !!

This bug appears to be happening for me on Magento installs on PHP 5.4 and above.

Change

abstract public function __construct();

to

abstract public function __construct($filePath);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.