如何在fpdf中的单元格中插入新行


how to insert new line into a cell in fpdf

我尝试过使用Ln((、MultiCell((或Write((,但总是遇到奇怪的问题。就像在第1行和第6列之后一样,循环中断,整个布局后退。

foreach($data as $row)
    {
    $room='-1010B';
    $labNo='(L1)';
    $this->SetFont('Arial','B',10);
    $this->Cell($w[0],15,$row[0],'LR',0,'C',$fill);
    $this->SetFont('Arial','',10);
    $this->Cell($w[1]+$w[2],15,$row[1]. " " .$room,'LR',0,'C',$fill);
    $this->Cell($w[3],15,$row[3]. " " .$room,'LR',0,'C',$fill);
    $this->Cell($w[4],15,$row[4]. " " .$room,'LR',0,'C',$fill);
    $this->SetFont('Arial','B',9);
    $this->Cell($w[5],15,$row[5],'LR',0,'C',$fill);
    $this->SetFont('Arial','',10);
    if($row[6]!="")
        $this->Cell($w[6],15,$row[6]. " " .$room,'LR',0,'C',$fill);
    else
        $this->Cell($w[6],15,$row[6],'LR',0,'C',$fill);
    $this->Cell($w[7]+$w[8]+$w[9],15,$row[7],'LR',0,'C',$fill);
   $flag++;
    $this->Ln();

    $fill =! $fill;
    }

查看fpdf.org 上的示例脚本

http://fpdf.org/en/script/script3.php

您需要为每一行创建一个数组,并使用函数Row((为您处理多行。

要插入新行,请使用'n,例如:This is a'n2 line example

在我的案例中,符号@起作用。

使用方法WrapCell:

e.g. WrapCell(20, 8, "first line@second line");
$pdf->SetXY(10, 44);
$pdf->cell(190,0,'',1);