public void writeCells(float xPos, float yPos, PdfContentByte[] canvases) { if (!calculated) { calculateHeights(); } for (int k = 0; k < cells.Length; ++k) { PdfPCell cell = cells[k]; if (cell == null) { continue; } writeBorderAndBackgroung(xPos, yPos, cell, canvases); PdfPTable table = cell.Table; float tly = 0; switch (cell.VerticalAlignment) { case Element.ALIGN_BOTTOM: tly = cell.Top + yPos - maxHeight + cell.Height - cell.PaddingTop; break; case Element.ALIGN_MIDDLE: tly = cell.Top + yPos + (cell.Height - maxHeight) / 2 - cell.PaddingTop; break; default: tly = cell.Top + yPos - cell.PaddingTop; break; } if (table == null) { float fixedHeight = cell.FixedHeight; float rightLimit = cell.Right + xPos - cell.PaddingRight; float leftLimit = cell.Left + xPos + cell.PaddingLeft; if (cell.isNoWrap()) { switch (cell.HorizontalAlignment) { case Element.ALIGN_CENTER: rightLimit += 10000; leftLimit -= 10000; break; case Element.ALIGN_RIGHT: leftLimit -= 20000; break; default: rightLimit += 20000; break; } } ColumnText ct = new ColumnText(canvases[PdfPTable.TEXTCANVAS]); float bry = -20000; if (fixedHeight > 0) { if (cell.Height > maxHeight) { tly = cell.Top + yPos - cell.PaddingTop; bry = cell.Top + yPos - maxHeight + cell.PaddingBottom; } } ct.setSimpleColumn(cell.Phrase, leftLimit, tly, rightLimit, bry, 0, cell.HorizontalAlignment); ct.setLeading(cell.Leading, cell.MultipliedLeading); ct.Indent = cell.Indent; ct.ExtraParagraphSpace = cell.ExtraParagraphSpace; ct.FollowingIndent = cell.FollowingIndent; ct.RightIndent = cell.RightIndent; ct.SpaceCharRatio = cell.SpaceCharRatio; ct.RunDirection = cell.RunDirection; try { ct.go(); } catch (DocumentException e) { throw e; } } else { float remainingHeight = 0; float maxLastRow = 0; //add by Jin-Hsia Yang, to add remaining height to last row if (table.Size > 0) { PdfPRow row = table.getRow(table.Size - 1); remainingHeight = maxHeight - table.TotalHeight - cell.PaddingBottom - cell.PaddingTop; if (remainingHeight > 0) { maxLastRow = row.MaxHeights; row.MaxHeights = row.MaxHeights + remainingHeight; //table.setTotalHeight(table.TotalHeight + remainingHeight); } } //end add table.writeSelectedRows(0, -1, cell.Left + xPos + cell.PaddingLeft, tly, canvases); if (remainingHeight > 0) { table.getRow(table.Size - 1).MaxHeights = maxLastRow; } } } }
public float calculateHeights() { maxHeight = 0; for (int k = 0; k < cells.Length; ++k) { PdfPCell cell = cells[k]; if (cell == null) { continue; } PdfPTable table = cell.Table; if (table == null) { float rightLimit = cell.isNoWrap() ? 20000 : cell.Right - cell.PaddingRight; ColumnText ct = new ColumnText(null); ct.setSimpleColumn(cell.Phrase, cell.Left + cell.PaddingLeft, cell.Top - cell.PaddingTop, rightLimit, -20000, 0, cell.HorizontalAlignment); ct.setLeading(cell.Leading, cell.MultipliedLeading); ct.Indent = cell.Indent; ct.ExtraParagraphSpace = cell.ExtraParagraphSpace; ct.FollowingIndent = cell.FollowingIndent; ct.RightIndent = cell.RightIndent; ct.RunDirection = cell.RunDirection; try { ct.go(true); } catch (DocumentException e) { throw e; } float yLine = ct.YLine; cell.Bottom = yLine - cell.PaddingBottom; } else { table.TotalWidth = cell.Right - cell.PaddingRight - cell.PaddingLeft - cell.Left; cell.Bottom = cell.Top - cell.PaddingTop - cell.PaddingBottom - table.TotalHeight; } float height = cell.FixedHeight; if (height <= 0) { height = cell.Height; } if (height < cell.FixedHeight) { height = cell.FixedHeight; } else if (height < cell.MinimumHeight) { height = cell.MinimumHeight; } if (height > maxHeight) { maxHeight = height; } } calculated = true; return(maxHeight); }