Rowspan Does Not Work in Itextsharp

Itextsharp RowSpan missing? no definition for rowspan

See this forum question discussing the different iTextSharp versions. It should work in the latest iTextsharp version.

Rowspan with iTextSharp doesn't work properly

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.

hth

Mario

itextsharp: rowspan doesn't work

Your cell "Riepilogo missioni valori dal " only spans 13 columns. PdfPTable requires that you fill in the rest of those columns (4) at the end of your current row before it will jump to the next row of 17 columns.

To fill in the end of your row, you can either add 4 empty cells or use the CompleteRow method.

table.AddCell("")
table.AddCell("")
table.AddCell("")
table.AddCell("")

or

table.CompleteRow()

iText: Cell with Image doesn't apply Rowspan

In case you wonder why nobody is answering your question. That's simple: the problem you describe can not be reproduced. I have taken your code snippet, and I have created the following standalone example:

PdfPTable table = new PdfPTable(2);
PdfPCell imageCell = new PdfPCell();
imageCell.addElement(Image.getInstance(IMG));
imageCell.setRowspan(2);
table.addCell(imageCell);
table.addCell(new Phrase("1"));
table.addCell(new Phrase("2"));

For the full source code, see ImageRowspan

The resulting PDF looks like this:

Sample Image

As you can see, the table has two columns and two rows. The first cell (the one with the image) spans two rows. You can download cmp_image_rowspan.pdf from out git repository.



Related Topics



Leave a reply



Submit