I am attempting to Span a Cell over 2 rows and I can do it without issue if the cell is not on the first row of the table, but as soon as I set RowSpan = 2 on a cell in the first row an exception is thrown in the Save Method. This code is copied from a response on this forum regarding RowSpan that I have altered to to provide an example:
var document = new Document();
var page = document.Pages.Add();
page.PageInfo.Height = 711f + 9f + 9f;
page.PageInfo.Width = 468f + 9f;
//page.MediaBox = new Rectangle(0,0,477,729);
//page.BleedBox = new Rectangle(9, 9, 477, 720);
page.TrimBox = new Rectangle(9f, 720f, 468f + 9f, 9f);
page.PageInfo.Margin = new MarginInfo { Bottom = 0, Top = 0, Left = 0, Right = 0 };
var tab1 = new Table();
//Add the table in paragraphs collection of the desired page
page.Paragraphs.Add(tab1);
//Set with column widths of the table
tab1.ColumnWidths = “120 120 120”;
//Set default cell border using BorderInfo object
tab1.DefaultCellBorder = new BorderInfo(BorderSide.All, 0.1F, Color.Red);
//Set table border using another customized BorderInfo object
tab1.Border = new BorderInfo(BorderSide.All, 1F, Color.Blue);
//Create MarginInfo object and set its left, bottom, right and top margins
var margin = new MarginInfo();
margin.Top = 5f;
margin.Left = 5f;
margin.Right = 5f;
margin.Bottom = 5f;
//Set the default cell padding to the MarginInfo object
tab1.DefaultCellPadding = margin;
var row1 = tab1.Rows.Add();
var cell1 = new Cell();
cell1.Paragraphs.Add(new TextFragment(“Column 1” ));
row1.Cells.Add(cell1);
//Create rows in the table and then cells in the rows
row1.Cells.Add(“col2”);
row1.Cells.Add(“Should span 2 Rows”);
row1.Cells[2].RowSpan = 2;
var row2 = tab1.Rows.Add();
row2.Cells.Add(“item1”);
row2.Cells.Add(“item2”);
row2.Cells.Add(“item3”);
var row3 = tab1.Rows.Add();
// set the default cell border for row as None
row3.DefaultCellBorder = new BorderInfo((int) BorderSide.None);
row3.Cells.Add(“item1”);
row3.Cells[0].IsNoBorder = true; //Set the border for cell0 as None
row3.Cells.Add(“item2”);
row3.Cells.Add(“item3”);
row3.Cells[2].IsNoBorder = true; //Set the border for cell2 as None
//row3.Cells[2].RowSpan = 2;
var row4 = tab1.Rows.Add();
row4.Cells.Add(“item1”);
row4.Cells.Add(“item2”);
row4.Cells.Add(“item3”);
document.Save(myDir+@“RowSpan_Border_Test.pdf”);
Thanks in advance.
Jon