Reputation: 53
I'm trying to create a simple table with iTextSharp, so with C#. The goal is a table like this one:
The problem is that if I apply the rowspan as 2 on cell A, iTextSharp does not render the rowspanned cell, this means that the cell have the same height of cell B. Here's the code:
PdfPTable corporateTable = new PdfPTable(2);
corporateTable.HeaderRows = 1;
corporateTable.TotalWidth = pdfWidth - 50;
PdfPCell vCell = new PdfPCell();
vCell.Border = Rectangle.BOX;
vCell.Rowspan = 2;
vCell.Phrase = new Phrase("A", new Font(fontLh, 7f, 1, BaseColor.BLACK));
corporateTable.CompleteRow();
corporateTable.AddCell(vCell);
PdfPCell vCellx = new PdfPCell();
vCellx.Phrase = new Phrase("B", new Font(fontLh, 7f, 1, BaseColor.BLACK));
vCellx.Colspan = 3;
corporateTable.AddCell(vCellx);
PdfPCell vCell1 = new PdfPCell();
vCell1.Phrase = new Phrase("C", new Font(fontValue, 7f, 0, BaseColor.BLACK));
corporateTable.AddCell(vCell1);
corporateTable.WriteSelectedRows(0, -1, 100f, 100f, writer.DirectContent);
document.Close();
What's wrong? I'm using the latest version of the dll.
Upvotes: 4
Views: 12471
Reputation: 1
The problem is at
vCellx.Colspan = 3;
Use
vCellx.Colspan = 1;
because you declared pdf table with two columns. You already added one column with rowspan 3 so you have only another one column and not three columns
Upvotes: 0
Reputation: 1994
I think it will work. Try to remove following code rows:
corporateTable.CompleteRow();
...
vCellx.Colspan = 3;
Upvotes: 1
Reputation: 4859
Well the basic answer is: it works! if you add two more cells, you will see that one cell (the one underneath A) is not filled.
But this is not what you expect (nor did I btw). To achive what you want use nested tables, that means:
search for itext rowspan, you will find multiple fully typed out examples.
hth
Mario
Upvotes: 5