2013-08-07 43 views
1

如何更改TCPDF中的阿拉伯數字&波斯數字,我是否需要更改編碼或char代碼?如何更改TCPDF中的阿拉伯數字和波斯數字

我需要用۱代替1,這是unicode中的阿拉伯語代碼。

我發現這個代碼,但我不知道如何使用它

function formatPageNumber($num) { 
$strnum = strval($num); 
$strnum = preg_replace_callback("/[0-9]/", create_function('$matches', ' 
$numarr = array("۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"); 
return $numarr[intval($matches[0])];'), $strnum); 
return $strnum; 
} 
+0

爲什麼你不使用阿拉伯字體? http://stackoverflow.com/questions/5080669/tcpdf-very-slow-generation-of-dynamic-arabic-pdf – Sbml

+0

這些不是阿拉伯語,但波斯數字,並不會在任何阿拉伯字體中找到。 –

+0

好的,在這種情況下,請在 – Sbml

回答

2

試試這個:

require_once('tcpdf/config/lang/eng.php'); 
require_once('tcpdf/tcpdf.php'); 

function formatPageNumber($num) { 
$strnum = strval($num); 
$strnum = preg_replace_callback("/[0-9]/", create_function('$matches', ' 
$numarr = array("۰", "۱", "۲", "۳", "۴", "۵", "۶", "۷", "۸", "۹"); 
return $numarr[intval($matches[0])];'), $strnum); 
return $strnum; 
} 

// create new PDF document 
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 

// set font 
$pdf->SetFont('dejavusans', '', 10); 

// add a page 
$pdf->AddPage(); 

// define some HTML content with style 
$html = formatPageNumber("This is my test string number 1724"); 

// output the HTML content 
$pdf->writeHTML($html, true, false, true, false, ''); 

// reset pointer to the last page 
$pdf->lastPage(); 

//Close and output PDF document 
$pdf->Output('test.pdf', 'I'); 
+0

以下看到我的回答嗨,好的,但是如果我想寫波斯語文本,方向就會中斷 –

+0

這只是一個例子,您可以只將函數放入要轉換的數字中,像這樣:$ html ='這是我的測試字符串號碼'。 formatPageNumber( '1724'); – Sbml

相關問題