fpdf line break not working

2019-08-02 03:55发布

问题:

I have a knockout observable which contains a text that has line breaks in it.

Like this:

 var  str += item.first_name +  " " + item.last_name + "," + item.occupation + "\n\n"; 
 str += "RE :" + item.first_name +  " " + item.last_name + ", DOB: "
                            + item.date_of_birth + "\n"; 
text = ko.observable(str); 

The method that I am using to display the string is:

$pdf->MultiCell(0,8,$text);

The result that I get in my pdf is :

 Dr. Bart grahamson,MBBSRE :Jack Junior, DOB: 1985-01-02

What is a way to catch those line breaks?

回答1:

Use \n and \r.

var  str += item.first_name +  " " + item.last_name + "," + item.occupation + "\n \r\r \n"; 
 str += "RE :" + item.first_name +  " " + item.last_name + ", DOB: "
                            + item.date_of_birth + "\n \r"; 
text = ko.observable(str);