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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16364414/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:59:33  来源:igfitidea点击:

how to insert new line into a cell in fpdf

phppdffpdf

提问by bagaria

I have tried using Ln(), MultiCell() or Write(), but I always get weird problems. Like after the 1st row and 6th column, the loops breaks, and the entire layout falls back.

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

    }

采纳答案by bones

Take a look at the sample script on fpdf.org

查看 fpdf.org 上的示例脚本

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

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

You'll want to create an array for each line and use the function Row() which handles multiple lines for you.

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

To insert a new line use \nfor example: This is a\n2 line example

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

回答by Sergej Karavajnij

In my case symbol @worked.

就我而言,符号@起作用了。

Using method WrapCell:

使用方法 WrapCell:

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

回答by user4582872

$pdf->SetXY(10, 44);
$pdf->cell(190,0,'',1);