Alberto Sartori Alberto Sartori - 4 years ago 223
C# Question

Rowspan with iTextSharp doesn't work properly

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));

PdfPCell vCellx = new PdfPCell();
vCellx.Phrase = new Phrase("B", new Font(fontLh, 7f, 1, BaseColor.BLACK));
vCellx.Colspan = 3;

PdfPCell vCell1 = new PdfPCell();
vCell1.Phrase = new Phrase("C", new Font(fontValue, 7f, 0, BaseColor.BLACK));

corporateTable.WriteSelectedRows(0, -1, 100f, 100f, writer.DirectContent);

What's wrong? I'm using the latest version of the dll.

Answer Source

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:

  • create a table with two cols
  • insert cell A into table
  • create cell 2
  • create one more table with 1 col
    • insert cell B into table 2
    • insert cell c into table 2
  • insert table 2 into cell 2

search for itext rowspan, you will find multiple fully typed out examples.



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download