单元格宽度 = 文本宽度 FPDF

Cell width = text width FPDF

我制作了一个 PDF 导出器,它从模型中获取数据并通过 FPDF 库将其导出为 PDF。

$pdf = new FPDF();
$pdf->AddPage();

foreach ( $finalData AS $finalRow )
{
    foreach($finalRow as $one)
    {
        $pdf->SetFont("Arial", "", "8");
        $pdf->Cell(18, 5, $one, 1, 0, "C");
    }
    $pdf->Ln();
}

$pdf->Output();`

但是我的信息太多了,我的信息不会从单元格边框中消失的唯一方法是使我的单元格宽度等于文本(因为在某些列中有短文本,而在某些列中有长文本).有人知道怎么做吗???

你想要FPDF::GetStringWidth吗?

http://www.fpdf.org/en/doc/getstringwidth.htm

你可以使用这段代码来解决这个问题。

$pdf->CellFit(35,19,"Message typed here for test only",1,0,'C',0,'',1,0);

检查这个 URL how to auto adjust cell width in fpdf using php and mysql

来源:http://www.fpdf.org/en/script/script62.php