Limitation of this code is, we need to specify a fixed height ($yH) for the table row in this code.

It is not possible to specify this height value if you don't have any clue about length of the dynamically generated text.

In this case we need to add a piece of code to set the $yH value dynamically.

i-e The code should measure the height of the cell for each column using GetY() method. i-e we need to find the difference by calling the GetY() before and after calling the MultiCell method.

Then we need to find the largest $yH among all columns. This largest value should be used as $yH when actually creating the table.

i-e We need to use the code two times, one time for finding the appropriate height and another time for creating table using the found height.

If you know any simple way to achieve all these things you can share it thro' the comments.

The above sample code will create issue if the pdf content grows more than one page.

In this case we need to call addPage() for every page of the content.

In our settings, each page hold 7 rows of data. So I have updated the code to call addPage() on every 7th row using modulo operator. And, we need to call at end of the all rows also in addition to call it at every 7th row.

3 comments:

Actually you can measure the height of the cells by trying to find the highest height when creating the cells of the row and after calling a function to draw the borders, using as height to create the bordes the difference between the highest height found and an Y saved before drawning the data.

I don't know if Marco's suggestion would work, but the way I implemented the flexible height was by using 3 for loops. One draws MultiCells to calculate the max height. Previously you store the original x and y in some variables. Another for loop draws Cells using the max height, starting from the original x and y (this effectively overwrites the first MultiCells). Finally you use another for loop to write the MultiCells once again and at the same x and y co-ordinates. It's very inefficient but it is the only way I could figure out to do it. Anyway, FPDF is a very primitive library and it's not maintained anymore; so, not much can be expected from it.