Magento打印(配送单、退款单、发票)时PDF中的乱码问题

来源:互联网 发布:淘宝面膜机危害 编辑:程序博客网 时间:2024/04/29 00:28


我使用Magento1.4.2,在其自带的TTF文件不能很好地解析中文字符,TTF文件的位置在网站根目录下的/lib/LinLibertineFont/中。打印的中文字符都是这样的



解决方法:

1.在Windows下复制一个MSYHBD.TTF(微软雅黑)至网站根目录下的/lib/LinLibertineFont/中

2.修改app\code\core\Mage\Sales\Model\Order\Pdf\Abstract.php

 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/MSYHBD.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/MSYHBD.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/MSYHBD.TTF');        $object->setFont($font, $size);        return $font;    }
注:这里主要是讲解解决方法,实际修改请将上述方法写成插件的形式,不要破坏Magento的产品代码。