9

I would like to add an array of PDFPCells to a PDFPRow, then add the PDFPRow to a PDFPTable, but I can't seem to find a method within PDFPTable for this.

There is however a PDFPTable.AddCell

Any ideas?

Since_2008
  • 2,331
  • 8
  • 38
  • 68

1 Answers1

13

Check out the PdfPTable's Rows.Add() method which takes a PdfPRow, which you can construct using an array of PdfPCells.

Example:

// ...
PdfPTable table = new PdfPTable(5);
PdfPCell[] cells = new PdfPCell[] { new PdfPCell(GetCell("c1")),
                                    new PdfPCell(GetCell("c2")),
                                    new PdfPCell(GetCell("c3")),
                                    new PdfPCell(GetCell("c4")),
                                    new PdfPCell(GetCell("c5"))};
PdfPRow row = new PdfPRow(cells);
table.Rows.Add(row);
// ...

Where the method GetCell() returns a PdfPCell.

Jay Riggs
  • 53,046
  • 9
  • 139
  • 151
  • I also prefer the approach Kukoy is seeking. I tried @Jay Rigg's code, but often ends in an error which says Can't access the file that has been closed. The problem is iTextSharp does not encourage this approach according to Bruno http://stackoverflow.com/a/19874992/97109. I wonder why. – Stack0verflow Mar 19 '14 at 18:52