Reputation: 811
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
Reputation: 67
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
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