【问题标题】:how to insert new line into a cell in fpdf如何在fpdf中的单元格中插入新行
【发布时间】:2013-05-03 17:19:59
【问题描述】:

我尝试过使用 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;

    }

【问题讨论】:

    标签: php pdf fpdf


    【解决方案1】:

    查看 fpdf.org 上的示例脚本

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

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

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

    【讨论】:

    • \n 不适用于 Cell() 或 MultiCell() ,但如果您使用 MultiCell() 则按 Enter 就足够了。
    【解决方案2】:

    在我的例子中,符号 @ 有效。

    使用WrapCell方法:

    e.g. WrapCell(20, 8, "first line@second line");
    

    【讨论】:

    • 对不起,伙计们。 WrapCell 是我前任写的 Wrap 方法——它不在 fpdf.php 中……
    【解决方案3】:
    $pdf->SetXY(10, 44);
    $pdf->cell(190,0,'',1);
    

    【讨论】:

    • 你能解释一下你写了什么吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-18
    • 1970-01-01
    相关资源
    最近更新 更多