FPDF and wrapping in cells

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

FPDF and wrapping in cells

Post by Ree »

I am having a problem making text wrap in cells with FPDF. In FPDF documentation it is mentioned that MultiCell() can be used for this, but I don't find it useful when building tables because it messes things up. For example, you need to display a user table with names and emails:

Code: Select all

$pdf->Cell(150, 12, 'Name', 1, 0);
$pdf->Cell(100, 12, 'Email', 1, 0);
$pdf->Ln();
foreach ($users as $user)
{
  $pdf->Cell(150, 12, $user->getName(), 1, 0);
  $pdf->Cell(100, 12, $user->getEmail(), 1, 0);
  $pdf->Ln();
}
In the example above if one of the names is too long to fit inside the Name cell, it will be printed on top of the Email cell. If MultiCell() was used in the same example, names would be wrapped inside Name cells, but the table wouldn't look like a table since all of the cells would be printed one below another.

Is there a way to generate tables with FPDF so that the text in cells would wrap automatically?
Post Reply