Change the Language in Magento PDF


Why doesn’t my language show up in Magento PDF files?

Well it’s probably because you don’t have a font in your language uploaded to your Magento installation. And if that’s the case then you haven’t told Magento where to find it. The fix is rather simple. The first step in is to copy files from the Magento core into a local folder to make this change upgrade proof.

Step 1: Navigate to app/code/core/Mage/Sales/Model/Pdf and then copy Abstract.php, Creditmemo.php, Invoice.php, and Shipment.php files to app/code/local/Mage/Sales/Model/Pdf.

How to add my language to Magento Abstract.php

Now open up Abstract.php and find the following code around line 562:

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

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

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

Step 2: Replace the above code with the following code. Don’t worry! If for some odd reason your Magento install breaks after this change, you can simple rename or delete this edited file and the version sitting in the core will take over.

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

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

 protected function _setFontItalic($object, $size = 7)
 {
 //$font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/LinLibertine_It-2.8.2.ttf');
 $font = Zend_Pdf_Font::fontWithPath(Mage::getBaseDir() . '/lib/LinLibertineFont/BiauKai.ttf');
 $object->setFont($font, $size);
 return $font;
 }
Icon from Nuvola icon theme for KDE 3.x.
Image via Wikipedia

Notice I commented out the LinLibertine font and added BiauKai.ttf to support Traditional Chinese text in my Magento PDF print outs. You can replace that font with any TrueType font of your language. You can also change the default font size simply by changing the $size = 7 to something like $size = 10. Don’t go too big or the text in your print outs might overlap.

Step 3: Now it’s time to upload your TrueType font to the /lib/LinLibertineFont/ folder. Make sure you are uploading a .ttf file or you will get an error in Magento. After the upload is complete, run to your Magento admin panel and print out an invoice in your language.

Magic!

Search

Search
On Key

Related Posts

APPSeCONNECT is now a completely new entity headquartered in the US! 🇺🇸