문제

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.

도움이 되었습니까?

해결책

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).

다른 팁

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.

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);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top