[VtigerCRM][修改] Vtiger 5.4.0 內建的PDF相關調整

(2013.04.23 -  靠腰,整理網誌不小心誤砍,blogger介面管理真爛,好險還可以馬上去google暫存,成也谷哥敗也谷歌....,留言的部分就不還原了m-_-m)

本篇將根據我調整"Quote報價單PDF"的過程經驗進行分享,解釋過程初步只會根據我會將碰到的問題來說明。如果您有其他需求問題不會修改可跟我反應,當我覺得有修改自用參考價值時,很樂意幫你研究PO文!


解決PDF的中文亂碼問題
Vtiger 5.4.0的Source Code版之中已經包含較新的TCPDF模組並支援中文化的顯示,由於預設生成PDF的過程中無法對應到中文字體的顯示字型。只要做一個修改引導正確字型的動作即可解決,相較於過去舊版的中文化過程來的輕快。

另外注意的是字型會影響PDF的檔案大小,建議使用msungstdlight的adobe字型(已內建)來呈現繁體中文,而大陸論壇所推薦的stsongstdlight字型是簡體中文,請不要搞混。

只修改./vtlib/Vtiger/PDF/TCPDF.php當中大約第75~76行,增加$family = 'msungstdlight';即可,其餘不用調整,即能解決5.4.0的PDF中文亂碼問題

68:      function SetFont($family, $style='', $size='') {  
69:          if($family == '') {  
70:              $family = $this->FontFamily;  
71:          }  
72:          //Select a font; size given in points  
73:          if ($size == 0) {  
74:              $size = $this->FontSizePt;  
75:          }  
76:          $family = 'msungstdlight'; //中文化需添加此項  
77:          // try to add font (if not already added)  
78:          $fontdata = $this->AddFont($family, $style);  
79:          $this->FontFamily = $fontdata['family'];  
80:          $this->FontStyle = $fontdata['style'];  
81:          $this->CurrentFont = &$this->fonts[$fontdata['fontkey']];  
82:          $this->SetFontSize($size);  
83:      }  


調整Quotes PDF的中文翻譯
如果你需要重譯 Quote報價單的中文字或者調整名詞意思,可對下列兩處進行調整。這兩者差別在於前者是Quotes當中的變數翻譯,後者是輸出翻譯。
modules/Quotes/language/zh-tw.lang.php
include/language/zh_tw.lang.php

舉例來說,我想在報價PDF上調整"聯繫人姓名"改為"聯絡人",從modules/Quotes/language/zh-tw.lang.php可以找到這個已存在的變數翻譯...
'Contact Name' => '聯繫人姓名',
後來我想調整"Grand Total : (in NT$)"這相關字眼卻找不到,反而只有在include/InventoryPDFController.php當中找到關鍵...
$summaryModel->set(getTranslatedString("Grand Total : (in $currencySymbol)", $this->moduleName), $this->formatPrice($final_details['grandTotal'])); 
乾脆不如等到最後字串Print之前再翻譯,在include/language/zh_tw.lang.php裡添加...
"Grand Total : (in NT$)" => '總計 NT$:',
這樣於Print之前一定會變成我想要的顯示,一般做法是從前者下手而找不到變數翻譯再從後者下手,避免不必要的翻譯影響效能,兩者前後差別在於原本的變數翻譯與事後轉換。當然你也可以乾脆在include/InventoryPDFController.php之中直接翻譯掉!

要注意哪一個變數對應到哪一個名詞,尋找過程是必須不斷Retry生成PDF後看到變化才找到變數,各位多試幾次找找看也無仿!


預設PDF調整方式

這裡又花我一堆時間驗證,在官方WiKi沒有特別解釋...之前有寫到一篇如何修改5.0.4的做法,5.2.0以上已經不適用以相同手法來修改,雖然Open Source好處可以讓你對原本的Code進行修改更改,但我看過程式邏輯後,變得比較制式且大調整有較高難度,這裡給需要的人參考記錄。在5.4.x的版本當中,你可以從下列位置來修改調整 (以下不適合5.1.x以前的版本)

1. 根據以下三處進行調整Header、Conten、Footer三處的顯示版面
vtlib\Vtiger\PDF\inventory\HeaderViewer.php
vtlib\Vtiger\PDF\inventory\ContentViewer.php
vtlib\Vtiger\PDF\inventory\FooterViewer.php

2. 再來你必須找到Database所匯出的數據,將被定義在此
include\InventoryPDFController.php

3. 最後每個模組有自己PDF的細節變化,以Quote為例
modules\quote\module\QuotePDFController.php

留言

  1. Sheet metallic fabrication is a process that includes numerous methods. While every comes with its own advantages, it’s essential to consider about|to contemplate} how these advantages apply to your specific design. Thanks for explaining that you will want to|it can CNC machining be finest to|you'll need to} attempt to make uniform bends in the metallic. Personally, I would need to get an expert to assist me do any fabrication work.

    回覆刪除

張貼留言

留言請注意禮節與尊重他人,良好的交流環境需要你我共同維護。

VtigerCRM 相關留言討論,請改至FaceBook社團申請加入使用
https://www.facebook.com/groups/vTigerCRMtoTaiwan/