FPDF相邻打印MultiCell()

时间:2012-11-26 05:50:39

标签: fpdf

我已经google了一下,发现这个问题很常见,但我似乎无法找到一个正确而直接的答案。我正在使用FPDF,我想使用MultiCell()生成表,因为我需要它的换行属性。试过Cell()但它无法读取换行符。

$col1="PILOT REMARKS\n\n";
$pdf->MultiCell(189, 10, $col1, 1, 1);
$col2="Pilot's Name and Signature\n".$name;
$pdf->MultiCell(63, 10, $col2, 1);
$pdf->Ln(0);
$col3="Date Prepared\n".$date;
$pdf->MultiCell(63, 10, $col3, 1);

但我无法正确生成它'因为MultiCell()会堆叠结果。如何以最简单,最简单的方式相互打印MultiCell()?

找到这个similar question,但它没有提供明确的答案。任何帮助将不胜感激。提前致谢。

4 个答案:

答案 0 :(得分:36)

尝试存储X和Y坐标,然后在写入

后设置它们
$x = $pdf->GetX();
$y = $pdf->GetY();

$col1="PILOT REMARKS\n\n";
$pdf->MultiCell(189, 10, $col1, 1, 1);

$pdf->SetXY($x + 189, $y);

$col2="Pilot's Name and Signature\n".$name;
$pdf->MultiCell(63, 10, $col2, 1);
$pdf->Ln(0);
$col3="Date Prepared\n".$date;
$pdf->MultiCell(63, 10, $col3, 1);

答案 1 :(得分:6)

只需添加到Danny's answer。我喜欢保存每列的宽度,然后在执行SetXY方法时使用它。

示例:

$x = $this->x;
$y = $this->y;
$push_right = 0;

$this->MultiCell($w = 100,3,"Column\r\nNumber 1",1,'C',1);

$push_right += $w;
$this->SetXY($x + $push_right, $y);

$this->MultiCell($w = 60,3,"Column\r\nNumber 2",1,'C',1);

$push_right += $w;
$this->SetXY($x + $push_right, $y);

$this->MultiCell(0,3,"Column 3\r\nFilling in the Rest",1,'C',1);

答案 2 :(得分:2)

您可以使用SetXY(x,y)函数将光标设置为pdf。

          $pdf->SetXY(x,y);

将光标设置为以pdf格式打印数据

其中x是x轴值,y是y轴值

答案 3 :(得分:0)

使用$pdf->Ln(10);$pdf->cell();

示例:

$pdf->cell(100,10,"your content");
$pdf->Ln(10);