【问题标题】:fpdf multicell is not generating same heightfpdf multicell 没有生成相同的高度
【发布时间】:2017-11-26 11:12:28
【问题描述】:

我写了下面的代码,它工作正常,但多单元格行高不能正常工作。我写了下面的代码,它工作正常,但多单元格行高不能正常工作。我写下面的代码,它工作正常,但多单元格行高是不能正常工作。

$x=$pdf->GetY();
$pdf->SetY($x+1);

include_once("config.php");
$result = mysqli_query($mysqli, "SELECT * FROM prd"); // using mysqli_query instead
$i = 1;
while($res = mysqli_fetch_array($result))
{

$current_y = $pdf->GetY();
    $current_x = $pdf->GetX();

    $pdf->MultiCell(30, 5, $i, 1, 'L');
    $end_y = $pdf->GetY();
$prdid = $res[0];
        $empid = $res[1];
        $specification = $res[2];
$prn = $res[3];



$current_x = $current_x + 30;
    $pdf->SetXY($current_x, $current_y); 
    $pdf->MultiCell(30, 5, $empid, 1, 'L');
    $end_y = ($pdf->GetY() > $end_y)?$pdf->GetY() : $end_y;

$current_x = $current_x + 30;
    $pdf->SetXY($current_x, $current_y);
    $pdf->MultiCell(30, 5, $specification, 1, 'L');
    $end_y = ($pdf->GetY() > $end_y)?$pdf->GetY() : $end_y;

$current_x = $current_x + 30;
    $pdf->SetXY($current_x, $current_y);
    $pdf->MultiCell(30, 5, $prn, 1, 'L');
    $end_y = ($pdf->GetY() > $end_y)?$pdf->GetY() : $end_y;


 $i++;
    $pdf->SetY($end_y);

        }
$pdf->Output();
?>

我的结果:

如何自动调整行高?

【问题讨论】:

    标签: php css row fpdf


    【解决方案1】:

    因此,多单元格本质上是动态的,即高度。您放入函数的高度是“行”高度。所以发生的事情是 fpdf 去写入多单元格,假设我们将高度定义为 5,它将创建一个高度为 5 的“单元格”并开始写入。然后它在宽度处遇到硬停并进入“我必须创建一个新行”,然后它在顶部“单元格”的正下方添加一个高度为 5 的新“单元格”。重复此过程,直到写出所有文本。显然,这对于动态内容非常有用,但也有您遇到的挑战。

    我一般采取的路径是记录起点,先写出多格,再记录终点。然后,您可以返回并编写其他单元格以更好地对齐。为此,GetX、GetY、SetX、SetY 将成为您的朋友。您可以通过简单的数学来动态设置高度等。

    “懒惰”选项是重新进行布局以允许文档缩放,即使用太长的多单元格并将其放在行下方,这样您将拥有:
    |1 |46 |PR2.....|
    |真长的文字 这将扩展 在这里|
    |2 |........

    希望能帮助你前进!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-13
      • 2014-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-29
      相关资源
      最近更新 更多