FPDF表格內中文換行

edited 十月 2013 in 進階PHP討論
我把

http://www.fpdf.org/en/script/script3.php
http://203.68.102.46/online_book/content.php?chapter_sn=55
結合在一起

輸出

<?php
require('chinese.php');
require('include/include_config.php');



//=====================================================================
$pdf=new PDF_Chinese('P','mm','A4');

$pdf->AddBig5Font();
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('Big5','',10);
$pdf->SetAutoPageBreak(true);
//=====================================================================
$db = & new dbLoad($dbHost,$dbUser,$dbPass,$dbName,$dbPort);
$sql="select a.ep_id,a.ep_inherit_no,a.ep_last_name,b.first_name_word,a.ep_sex,a.ep_birth_date,";
$sql.="c.city_name,a.ep_address,a.ep_tel,a.ep_family_id ";
$sql.="from entire_personnel_volume a,first_name b,city c ";
$sql.="where a.ep_first_name_id=b.first_name_id ";
$sql.="and a.ep_birth_place=c.city_id ";
$sql.="and a.ep_first_name_id='1'";
$result = $db->queryclass($sql);

//Cell(float w [, float h [, string txt [, mixed border [, int ln [, string align [, int fill [, mixed link]]]]]]])

$pdf->SetFontSize(10);
$pdf->SetWidths(array(20,20,15,20,20,50,20,20));
$pdf->Row(array('編號','姓名','性別','出生日期','出生地','住址','電話號碼','族普表'));



while ($row = $result->fetch())
{
$ep_id = $row;
$ep_inherit_no = $row;
$ep_last_name = $row;
$first_name_word = $row;
$ep_sex = iconv("UTF-8","BIG5",$row);
$ep_birth_date = $row;
$ep_birth_place = iconv("UTF-8","BIG5",$row);
$ep_address = iconv("UTF-8","BIG5",$row);
$ep_tel = $row;
$ep_family_id = $row;

$name = iconv("UTF-8","BIG5",$first_name_word.$ep_last_name);


$pdf->Row(array($ep_id,$name,$ep_sex,$ep_birth_date,$ep_birth_place,$ep_address,$ep_tel,$ep_family_id));

}
?>


就是我在表格內,有設定寬度,然後字過長就會換行,在英文上可以,
但是在中文上沒辦法換行,不知道有沒有人碰過這問題,我快瘋了

或是有哪位大大有更好的辦法

原始討論: http://twpug.net/x/modules/newbb/viewtopic.php?topic_id=2731

評論

  • edited 三月 2008
    改一下 Row 函式裡面
    中文字碼和Ascii要分開判斷..
    $ascii = (ord($c)<128);
    中文換行換行
    $l+= $ascii ? $cw[$c] : 1000;

    if($l<$wmax){
    }
    .
    .
    .
    .
    .
    $i++;
    這一行改成
    $i += $ascii ? 1 : 2;
Sign In or Register to comment.