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; }
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!
Related articles
- eBay to Acquire Open Source E-Commerce Platform Magento (webpronews.com)
- Facebook Acquires Sofa, Makers of Mac Apps (webpronews.com)