【问题标题】:Cell width = text width FPDF单元格宽度 = 文本宽度 FPDF
【发布时间】:2015-05-04 00:23:09
【问题描述】:

我制作了一个 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();`

但是我的信息太多,我的信息不会从单元格边框中删除的唯一方法是使我的单元格宽度等于文本(因为在某些列中存在短文本,而在某些列中很长)。有谁知道这是怎么做的???

【问题讨论】:

    标签: php pdf zend-framework export fpdf


    【解决方案1】:

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

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

    检查此网址 how to auto adjust cell width in fpdf using php and mysql

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

    【讨论】:

      【解决方案2】:

      你想要FPDF::GetStringWidth吗?

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

      【讨论】:

      • $pdf->Cell($pdf->GetStringWidth($one)+3, 5, $one, 1, 0, "C");谢谢你!
      • +3 可以替换为$pdf->cMargin * 2
      • GetStringWidth 函数返回的单位类型是什么?
      猜你喜欢
      • 2017-07-04
      • 2021-08-07
      • 2013-04-26
      • 1970-01-01
      • 2011-12-31
      • 2011-03-18
      • 1970-01-01
      • 1970-01-01
      • 2014-07-13
      相关资源
      最近更新 更多