【问题标题】:Multiple line content in cell fpdf单元格fpdf中的多行内容
【发布时间】:2018-04-27 04:41:22
【问题描述】:

我正在创建发票应用程序并使用 fpdf 和 https://github.com/farjadtahir/pdf-invoicr pdf-invoicr 类。它工作正常,但现在我在数据库中有多行内容,如地址,当我从表单中保存 textarea 内容时,它将使用 br 标签保存,

nl2br(htmlentities($address, ENT_QUOTES, 'UTF-8'));

当它传递给 fpdf cell 属性时,它使用 br 标记显示,我使用

str_ireplace('<br />', "\r\n", $address);

即使它没有显示在新行中,只需将 br 替换为空格。有没有办法在 cell

内的多行中打印值
foreach($this->items as $item) 
            {

                $cHeight = $cellHeight;
                $this->SetFont($this->font,'b',8);
                $this->SetTextColor(50,50,50);

                $cbgcolor = explode(",",$item['cbgcolor']);

                $this->SetFillColor($cbgcolor[0],$cbgcolor[1],$cbgcolor[2]);
                $this->Cell(1,$cHeight,'',0,0,'L',1);
                $x = $this->GetX();
                $this->Cell($this->firstColumnWidth,$cHeight,iconv("UTF-8", "ISO-8859-1",$item['item']),0,0,'L',1);

                $this->SetTextColor(50,50,50);
                $this->SetFont($this->font,'',8);
                $this->Cell($this->columnSpacing,$cHeight,'',0,0,'L',0);
                $this->Cell($this->secondColumnWidth,$cHeight,$item['quantity'],0,0,'L',1);

                $this->Cell($this->columnSpacing,$cHeight,'',0,0,'L',0);
                $this->Cell($this->priceColumnWidth,$cHeight,iconv('UTF-8', 'windows-1252', $this->currency.' '.number_format($item['price'],2,$this->referenceformat[0],$this->referenceformat[1])),0,0,'C',1);

                $this->Cell($this->columnSpacing,$cHeight,'',0,0,'L',0);
                $this->Cell($this->priceColumnWidth,$cHeight,iconv('UTF-8', 'windows-1252', $this->currency.' '.number_format($item['total'],2,$this->referenceformat[0],$this->referenceformat[1])),0,0,'C',1);
                $this->Ln();
                $this->Ln($this->columnSpacing);
            }

这是我的身体..for $item['quantity'] 有多行内容。我将值打印为表格。因此,当我在一列中使用多单元格时,布局正在发生变化并且看起来不太好。

【问题讨论】:

  • 您能否显示您将此字符串添加到 PDF 中的代码,以便我们了解您所说的“单元格”是什么意思?

标签: php fpdf


【解决方案1】:

您可以使用MultiCell将文本换行在单元格中

$pdf-&gt;MultiCell( 200, 40, $address, 1);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多