donglun1918 2013-03-25 13:43
浏览 37
已采纳

FPDF表内容与单元格重叠

I want to create a something which could work like dynamic table. Could because I knew how many cells it would be, but kind of because content I put into cell could be different length. I have used code posted of fpdf site:

require('fpdf/fpdf.php');
class PDF extends FPDF{
function BasicTable($header, $data)
{
    // Header
    foreach($header as $col)
        $this->Cell(40,7,$col,1);
    $this->Ln();
    // Data
    foreach($data as $row)
    {
        foreach($row as $col)
            $this->Cell(40,6,$col,1);
        $this->Ln();
    }
}
}

and right now if i put into Table those values:

$header = array('Country', 'Capital', 'Area (sq km)', 'Pop. (thousands)');
$data =  array(array('a','a','a','a'), array('a','a','a','a'), array('a','a','a','a'), array('a','a','a','a'));
$pdf->SetY(45);
$pdf->BasicTable($header,$data);

everything is ok. But when I want to change my 'a' into something more complex, like sentence made of few words, my text is 'leaving' the cell and it start to overlap the next cell.

Is there a way in fpdf to autofit cell?

  • 写回答

1条回答 默认 最新

  • dongxing2263 2013-04-03 08:15
    关注

    You have to use FPDF::MultiCell() method, which is used to display multiline content.

    In MultiCell, text will wrap and you won't have that problem.

    You could also look at abstraction code over FPDF like PDML, or HTML2FPDF, or maybe TCPDF as stated before but i don't know this one.

    Good luck with your project.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C语言设计一个简单的自动换档程序
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。