Magento PDF發票,支持中文,以及修改的辦法

Magento PDF發票,支持中文,以及修改的辦法.php

 

若是讓magento的PDF發票支持中文.Magento生成PDF發票.使用的是zend framework的zend_pdf類.

下面是一個簡單的,使用zend framework生成pdf文件的用法.[code]<?php
...
// 建立一個新的PDF文檔.
$pdf1 = new Zend_Pdf();html

// 加載一個現有的PDF文件.
$pdf2 = Zend_Pdf::load($fileName);app

// 從字符串加載並生成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;
}code

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;
}htm

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;rem


}[/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

相關文章
相關標籤/搜索