/** * Wraps around the text in all cells so it fits the column width. * This method should be called after all calls to setColumnWidth and autoAdjustColumnWidths. */ public void WrapAroundCellText() { List <List <Cell> > tableData2 = new List <List <Cell> >(); for (int i = 0; i < tableData.Count; i++) { List <Cell> row = tableData[i]; for (int j = 0; j < row.Count; j++) { Cell cell = row[j]; int colspan = cell.GetColSpan(); for (int n = 1; n < colspan; n++) { Cell next = row[j + n]; cell.SetWidth(cell.GetWidth() + next.GetWidth()); next.SetWidth(0f); } } } // Adjust the number of header rows automatically! numOfHeaderRows = GetNumHeaderRows(); rendered = numOfHeaderRows; AddExtraTableRows(tableData2); for (int i = 0; i < tableData2.Count; i++) { List <Cell> row = tableData2[i]; for (int j = 0; j < row.Count; j++) { Cell cell = row[j]; if (cell.text != null) { int n = 0; float effectiveWidth = cell.width - (cell.leftPadding + cell.rightPadding); String[] tokens = TextUtils.SplitTextIntoTokens( cell.text, cell.font, cell.fallbackFont, effectiveWidth); StringBuilder buf = new StringBuilder(); foreach (String token in tokens) { if (cell.font.StringWidth(cell.fallbackFont, (buf.ToString() + " " + token).Trim()) > effectiveWidth) { tableData2[i + n][j].SetText(buf.ToString().Trim()); buf = new StringBuilder(token); n++; } else { buf.Append(" "); buf.Append(token); } } tableData2[i + n][j].SetText(buf.ToString().Trim()); } else { tableData2[i][j].SetCompositeTextLine(cell.GetCompositeTextLine()); } } } tableData = tableData2; }