码迷,mamicode.com
首页 > 其他好文 > 详细

Magento PDF发票,支持中文,以及修改的办法

时间:2014-09-20 01:08:26      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:http   color   io   使用   ar   文件   div   art   sp   

Magento PDF发票,支持中文,以及修改的办法.

 

如果让magento的PDF发票支持中文.Magento生成PDF发票.使用的是zend framework的zend_pdf类.

下面是一个简单的,使用zend framework生成pdf文件的用法.[code]<?php
...
// 创建一个新的PDF文档.
$pdf1 = new Zend_Pdf();

// 加载一个现有的PDF文件.
$pdf2 = Zend_Pdf::load($fileName);

// 从字符串加载并生成PDF文件.
$pdf3 = Zend_Pdf::parse($pdfString);[/code]okay..非常简单吧..
我们先来看如果让magento的PDF支持中文.
首先,我们要明白.Magento为什么不支持中文.. 其实zendcart还有joomla都存在这个问题.
是因为这些程序中,使用的文字库并不支持中文.so,我们只需要替换掉就可以了.

此类文件在这里:app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php
找到如下的代码:[code] 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/LinLibertine_Bd-2.8.1.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‘);
$object->setFont($font, $size);
return $font;


}[/code]okay..看到这里大家就知道怎么修改了吧..
只需要把字体的库文件替换一下就ok.

.说一下要实现的效果.
因为默认的pdf上,是没有store的名字或者域名的.
客户想在pdf上加上本网站的域名.这样好做区分.

先说个简单的办法.

我们打开:app/code/core/Mage/Sales/Model/Order/Pdf/Abstract.php.然后把这段代码加到[code]$page->drawText(Mage::helper(‘sales‘)->__(‘Website : ‘) . "你网站的域名", 400, 780, ‘UTF-8‘);[/code][code]$page->drawText(Mage::helper(‘sales‘)->__(‘Invoice # ‘) . $invoice->getIncrementId(), 35, 780, ‘UTF-8‘);[/code]的下面.
就可以了..
当然,如果觉得位置不够好.只需要修改一下坐标$page->drawText(Mage::helper(‘sales‘)->__(‘Website : ‘) . "你网站的域名", [color=Red]400[/color], [color=Red]780[/color], ‘UTF-8‘);
 

 

http://www.zencart-cn.com/zencart-cn-news/article-a-5689.html

Magento PDF发票,支持中文,以及修改的办法

标签:http   color   io   使用   ar   文件   div   art   sp   

原文地址:http://www.cnblogs.com/sunsoftware/p/3982740.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!