Question

I am trying to define the Padding of a serie of columns that will be pushed inside my PdfPTable...

this is my code:

PdfPTable table = new PdfPTable(6);
table.WidthPercentage = 100;
table.SetWidths(new float[]{25, 25, 16, 11, 11, 11});
table.DefaultCell.Padding = 3;

There are something wrong, because when the table is generated, it does not have padding in anywhere.

Thank you in advance.

Was it helpful?

Solution

See this post from the creator of iText. The DefaultCell only gets used when calling AddCell with a string, phrase, image or another table. When you manually create a cell using New PdfPCell() then the defaults aren't used.

EDIT

Here's a sample factory method:

private static PdfPCell CreateCell() {
    var c = new PdfPCell();
    c.Padding = 5;
    return c;
}

You can also skip the factory method if you're only setting properties and use object initialization:

var c = new PdfPCell() { Padding = 5 };
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top