public void printTable(PdfOutput output) { if (rows.Count == 0) { throw new Exception("Cannot print a table with no rows"); } //draw top table border output.SetColor(Color.Black); output.DrawLine(bordersX[0], output.drawY, bordersX[columnCount], output.drawY, cellBorderWidth); foreach (Row r in rows) { //compute row thickness before drawing, add page break if necessary double rowThickness = getRowThickness(output, r); if (output.drawY - rowThickness < 0) { output.appendPageBreak(); } if (r is RegularRow) { string[] rowVals = ((RegularRow)r).contents; //draw row background, if applicable double y = output.drawY; if (!r.background.Equals(Color.White)) { output.SetColor(r.background); output.FillRectangle(bordersX[0], output.drawY - rowThickness, bordersX[columnCount] - bordersX[0], rowThickness); output.drawY = y; output.SetColor(Color.Black); } //draw cell contents for (int col = 0; col < columnCount; col++) { output.DrawWrappedText( r.font, r.fontSize, bordersX[col] + cellPaddingLeft, output.drawY - cellContentsDy, bordersX[col + 1] - bordersX[col] - cellPaddingRight, TextJustify.Left, rowVals[col] == null ? "N/A" : rowVals[col]); output.drawY = y; } //draw cell borders for (int col = 0; col <= columnCount; col++) { output.DrawLine(bordersX[col], output.drawY, bordersX[col], output.drawY - rowThickness, cellBorderWidth); } output.DrawLine(bordersX[0], output.drawY - rowThickness, bordersX[columnCount], output.drawY - rowThickness, cellBorderWidth); //move down the page for the next row output.drawY -= rowThickness; } else if (r is MergedRow) { string content = ((MergedRow)r).contents; //draw row background, if applicable double y = output.drawY; if (!r.background.Equals(Color.White)) { output.SetColor(r.background); output.FillRectangle(bordersX[0], output.drawY - rowThickness, bordersX[columnCount] - bordersX[0], rowThickness); output.drawY = y; output.SetColor(Color.Black); } //draw cell content output.DrawWrappedText( r.font, r.fontSize, bordersX[0] + cellPaddingLeft, output.drawY - cellContentsDy, bordersX[columnCount] - bordersX[0] - cellPaddingRight, TextJustify.Left, content); output.drawY = y; //draw cell borders output.DrawLine(bordersX[0], output.drawY, bordersX[0], output.drawY - rowThickness, cellBorderWidth); output.DrawLine(bordersX[columnCount], output.drawY, bordersX[columnCount], output.drawY - rowThickness, cellBorderWidth); output.DrawLine(bordersX[0], output.drawY - rowThickness, bordersX[columnCount], output.drawY - rowThickness, cellBorderWidth); //move down the page for the next row output.drawY -= rowThickness; } else { throw new Exception("Unrecognized row subclass \"" + r.GetType() + "\""); } } }