Eddi
Eddi

Reputation: 811

Problems at displaying textareas in a .pdf

I have a form which contains a textarea with a width of 30 columns. This textarea and some other text should be displayed in a .pdf via FPDF. The textarea is displayed like this:

$text=$row->fehlerbeschreibung;
$text=str_replace(array("\r\n", "\n", "\r"),"",$text);
$pdf->MultiCell(0,6,$text);

You see that I would like to ignore the linebreaks which happen due to the width of 30 cols. But whenever you press enter to create a linebreak, the linebreak should be displayed. Are there any differences in the coding of linebreaks to avoid this problem? Or do you know another way?

Upvotes: 0

Views: 1888

Answers (4)

Doberon
Doberon

Reputation: 648

I recommended use the function nl2br()

Upvotes: 0

key
key

Reputation: 1404

Simply Use MultiCell

Example:

$this->MultiCell(60,5,$Variable);

Upvotes: 1

Consider your textarea field is history. So you can do is:

$lengthofhistory = strlen($_SESSION['history']); 
$pdf- >SetFont('Helvetica','',10); $start = 0; $space = 0;
for($i=0;$i<=$lengthofhistory;$i++)
{
$char = substr( $_SESSION['history'], $i, 1 );
if($char == ' ') { $space = $space + 1; 
if($space == 18) { $substring =   substr($_SESSION['history'],$start,$i- $start); 
$pdf->Cell(0,5,$substring,0,1,'L'); $start = $i+1; $space = 0; } }
}
$substring = substr($_SESSION['history'],$start,$lengthofcomplaints-$start);
$pdf->Cell(0,5,$substring,0,1,'L');

Upvotes: 0

Grant Carlisle
Grant Carlisle

Reputation: 173

linebreaks are only created when pressing enter so you should just split via

$array = explode("\n",$string);

Then loop through the array like this;

foreach($array  as $key => $item) {
$pdf->MultiCell(0,6,$item);
$pdf->Ln();
}

Upvotes: 1

Related Questions