Heim  >  Artikel  >  Backend-Entwicklung  >  php fpdf 怎么输出一个表头

php fpdf 怎么输出一个表头

WBOY
WBOYOriginal
2016-06-23 14:24:50882Durchsuche

我这边需要输出一个table,但是表头里的字可能会比较多,页面的宽度是固定的。所以肯定要用到MultiCell,求各位 怎么用 ,其实我用了,但是乱掉了。。。
我的代码:
$pdf->Cell(30,6,'field 1','L,T,B',0,'L',true);
$pdf->Cell(40,6,'field 2','T,B',0,'L',true);
foreach($fields as $key=>$val){
// $pdf->Cell($tax_width, 20, $book, 0, 'L'); 
   $pdf->MultiCell($tax_width,6,$key,'T,B',0,'C',true);
}

用cell,有可能字会覆盖,用MultiCell就成不了一个表头了,求解。。。


回复讨论(解决方案)

你需要在 $pdf->MultiCell($tax_width,6,$key,'T,B',0,'C',true);
之后(之前)指定当前位置

你需要在 $pdf->MultiCell($tax_width,6,$key,'T,B',0,'C',true);
之后(之前)指定当前位置

怎么指定呢,这个不好计算吧。。。表头部分字段是不一定,有多有少,有长有短,不知道怎么弄。。给点提示 该怎么定位?

本帖最后由 xuzuning 于 2013-10-22 17:20:40 编辑

不计算肯定是不行的!
$top = $pdf->gety(); //左上角的 Y 坐标$left = $pdf->getx(); //左上角的 X 坐标$height = 60; //表头高$width = 100; //列宽$ar = array('标题', '长标题长标题'); //列标题foreach($ar as $text) {  $h = $height / ceil($pdf->GetStringWidth($text) / $width); //计算分行后的行高  $pdf->multicell($width, $h, $text, 1, 'C');  $pdf->setxy($this->getx() + $width, $top); //定位到下一列}
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn