3

i am creating an invoice application and using fpdf and https://github.com/farjadtahir/pdf-invoicr pdf-invoicr class. Its working fine but now i have multi line content in database like address, when i am saving the textarea content from form it will save with br tag,

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

When it passes to fpdf cell attribute it displaying with br tag, the i use

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

Even after it not displaying in new line, just replacing br with space. Is there any way to print value in multi line inside 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);
            }

This is my body..for $item['quantity'] have multi line content. where i am printing values as a table.so when i use multicell in one column the layout is changing and not look good.

Niju
  • 63
  • 2
  • 2
  • 7
  • 1
    Can you show the code where you add this string to the PDF, so we can see what you mean by "cell"? – IMSoP Nov 14 '17 at 09:44

1 Answers1

8

You can wrap your text in cell by using MultiCell

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

Aiyaz Khorajia
  • 598
  • 2
  • 11
  • MultiCell seems to break table cell positioning. See https://stackoverflow.com/questions/11982375/placing-two-multicells-next-to-each-other-using-fpdf-in-php – Giorgio Barchiesi Nov 13 '22 at 08:14