I have mentioned the useful FPDF PHP PDF generating library before, but today I’m quickly going to point out how you can solve the problem of inserting extra long lines of text into a table and forcing the table to automatically wrap or linebreak all of your text without simply chopping it off at the end when it reaches the right hand border of the cell.
The solution to this is pretty simple and it involves dropping the use of the Cell() function and instead incorporating the MultiCell() call.
The MultiCell basically allows for the printing of text with line breaks. These line breaks can be automatic, in other words when the text hits the right border of the cell, or explicit, i.e. via the n control character.
The function cleverly automatically lays down as many cells as possible, one below the other and all without any input or direction from you. The cell block can then be frames and even have its background painted if you want.
Parameters are pretty self-explanatory. You can set the width of the cells, the height of the cells, the text to print, whether or not you want a border, how you want the text aligned and whether or not you want the background filled.
Putting this in code, you would get a call that looks something like this:
$pdf->MultiCell(275,7,’Insert your long string here’,1,’L’,false);
Related Link: http://www.fpdf.org/en/doc/multicell.htm