tags:

views:

425

answers:

1

how we display fpdf multicell in equal heights having different amount of content

A: 

Great question.

I solved it by going through each cell of data in your row that will be multicelled and determine the largest height of all these cells. This happens before you create your first cell in the 'row' and becomes the new height of your 'row'.

You can determine the height of a multicelled cell by using the GetStringWidth function in FPDF. Here's what some of my code looks like to do this for one cell (just do this for any other multicell content before you generate the row:

$row_height = 5; // set the default

// multicell content
$description = $row['desciption'];

// get column width from a column widths array
$column_width = $column_widths['description'];

$number_of_lines = ceil( $pdf->GetStringWidth($description) / ($column_width - 1) );
// I subtracted one from column width as a kind of cell padding

// height of resulting cell
$cell_height = 5; 
$height_of_cell = ceil( $number_of_lines * $cell_height ); 

// do this again for any other multicell cells (or create a function for more DRY code)

// and compare the cell_height with the row_height
if ( $cell_height > $row_height ) {
  $row_height = $cell_height;
}
Josh Pinter