Compute column widths in a HTML-like manner (based on cell contents)
- by cipak
Hi,
I have a grid of data that I want to export to RTF, PDF etc. using various (and not perfect) PHP converters/generators.
What I am missing most is the HTML table automatic adjustment of column widths based on the lengths of strings in the cells (strings contain line breaks which complicate things a bit, as they should be preserved).
I need an algorithm that, given the contents of the cells (plain text), a total width of the table and an average width of a character, would return a width for each column. I wouldn't want to reinvent the wheel if something is already available.
Of course it can't be perfect if the font is variable width, but an approximation would do just fine. Or maybe it could have a configurable table with widths for each character.
Any hint would be appreciated. Thank you.