php fpdf 如何輸出一個表頭

來源:互聯網
上載者:User
php fpdf 怎麼輸出一個表頭
我這邊需要輸出一個table,但是表頭裡的字可能會比較多,頁面的寬度是固定的。所以肯定要用到MultiCell,求各位 怎麼用 ,其實我用了,但是亂掉了。。。
My Code:
$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就成不了一個表頭了,求解。。。

分享到:


------解決方案--------------------
本帖最後由 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); //定位到下一列
}
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.