I\'m generating some PDF file on the fly using PHP. My problem is I need to insert line breaks in some part of the text that will be inserted in the PDF file. Something like
Your code reads
$pdf->InsertText('Line one\n\nLine two');
I don't know about the PDF library you're using but normally if you want \n to be interpreted as a line break you must use double quotes in PHP, e.g.
$pdf->InsertText("Line one\n\nLine two");
After having so many nightmares, I found a solution.
utf8_decode(chr(10))
I tried \n
, <br/>
and chr(10)
but nothing worked. Then I realized that it was utf-8
and just tried the above one. It works fine with MultiCell
but not with Cell
.
MultiCell($w, $h, 'text<br />', $border=0, $align='L', $fill=1, $ln=0,
$x='', $y='', $reseth=true, $reseth=0, $ishtml=true, $autopadding=true,
$maxh=0);
You can configure the MultiCell
to read html on a basic level.
Maybe it´s too late but I solved this issue in a very simple way,
I am using the Multicell option and the text come from a form, if I use an input field to get the text I can´t insert line breaks in any way, but if use a textarea field, the line breaks in the text area are line breaks in the multicell ... and that´s it, it works even if I use utf8_encode($text)
option to preserve accents
You state that
2 is the height of the multi-line text box
No it's not. 2 is the distance between lines of text.
I don't think there is a real way for calculating the height of the actual resulting text box, unless you use GetY()
and then subtract the original Y value used in your SetXY()
statement for placing the Multicell in the first place.
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(#);
$pdf->MultiCell($height,$width,"Line1 \nLine2 \nLine3",1,'C',1);
In every Column, before you set the X Position indicate first the Y position, so it became like this
Column 1
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(#);
$pdf->MultiCell($height,$width,"Line1 \nLine2 \nLine3",1,'C',1);
Column 2
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(#);
$pdf->MultiCell($height,$width,"Line1 \nLine2 \nLine3",1,'C',1);