ITextSharp - Use Colspan with PdfPow

I can create multiple rows if they contain the same number of columns:

table = new PdfPTable(3); var firstRowCell1 = new PdfPCell( new Phrase ("Row 1 - Column 1")); var firstRowCell2 = new PdfPCell( new Phrase ("Row 2 - Column 2")); var firstRowCell3 = new PdfPCell( new Phrase ("Row 3 - Column 3")); PdfPCell[] row1Cells = { firstRowCell1, firstLineRow2, firstRowCell3 }; var row1 = new PdfPRow(row1Cells); table.Rows.Add(row1); var nextRowCell1 = new PdfPCell( new Phrase ("Row 2 - Column 1")); var nextRowCell2 = new PdfPCell( new Phrase ("Row 2 - Column 2")); var nextRowCell3 = new PdfPCell( new Phrase ("Row 2 - Column 3")); PdfPCell[] row2Cells = { nextRowCell1, nextRowCell2, nextRowCell3 }; var row2 = new PdfPRow(row2Cells); table.Rows.Add(row2); 

This works great, giving me two rows with three columns.

enter image description here

However, if I want the first row to have only one long column using Colspan, it disappears:

 var table = new PdfPTable(3); var firstRowCell1 = new PdfPCell(new Phrase("Row 1 - Column 1")); firstRowCell1.Colspan = 3; PdfPCell[] row1Cells = { firstRowCell1 }; var row1 = new PdfPRow(row1Cells); deptHeaderTable.Rows.Add(row1); var nextRowCell1 = new PdfPCell(new Phrase("Row 2 - Column 1")); var nextRowCell2 = new PdfPCell(new Phrase("Row 2 - Column 2")); var nextRowCell3 = new PdfPCell(new Phrase("Row 2 - Column 3")); PdfPCell[] row2Cells = { nextRowCell1, nextRowCell2, nextRowCell3 }; var row2 = new PdfPRow(row2Cells); deptHeaderTable.Rows.Add(row2); 

enter image description here

There are no errors as it simply does not display.

Also, I am aware of table.AddCell, which automatically starts a new row when the table column limit is reached for the current row. However, I want to use PdfPRow, if at all possible.

Any help would be greatly appreciated.

+1
pdf-generation itextsharp rows pdfptable
source share
1 answer

It looks like you have read documentation that is not supported by the original iText developer (being me). Can I ask you for the URL where you found this documentation so that I can ask you to stop and abstain?

As for the answer to your question: please see the official documentation and you will find MyFirstTable . Based on this example, you can adapt your own code as follows:

 var table = new PdfPTable(3); var cell = new PdfPCell(new Phrase("Cell with colspan 3")); cell.Colspan = 3; table.AddCell(cell); table.AddCell("row 2; cell 1"); table.AddCell("row 2; cell 2"); table.AddCell("row 2; cell 3"); 

As you can see, there is no reason to use the PdfPRow class. The PdfPRow class PdfPRow used internally by iText, but as described in my book, developers using iText should not use this class in their code.

+12
source share

All Articles