2

Is it possible to add space between the elements of a cell (rows) in C#? I'm creating a pdf in visual studio 2012 and wanted to set some space between the rows. I have something like this:

PdfPTable cellTable = new PdfPTable(1);
PdfPCell cell= new PdfPCell();
for(i=0; i < 5; i++)
{
    var titleChunk = new Chunk(tittle[i], body);
    var descriptionChunk = new Chunk(" " description[i], body2);
    var phrase = new Phrase(titleChunk);
    phrase.Add(descriptionChunk);
    cell.AddElement(phrase);
}
cellTable.AddCell(cell);
  • 1
    You'll have to be more specific. *Padding* is space between the cell and its contents. *Spacing* is spacing between different cells. *Leading* is spacing between lines of content. Your title refers *padding*, your question refers to *spacing* (between the rows), but also to *leading* (between the elements). It's hard to answer a question if you're not using the correct terminology. – Bruno Lowagie Nov 24 '13 at 10:25
  • @BrunoLowagie I'll change the tittle then. The PdfTable has one cell and that cell is going to have a few elements in it (rows) I want to increase the blank area between those elements. Like a paragraph between them, but that that big of a height. – Micael Florêncio Nov 25 '13 at 09:24

1 Answers1

5

OK, I've made you an example named LeadingInCell:

PdfPCell cell = new PdfPCell();
Paragraph p;
p = new Paragraph(16, "paragraph 1: leading 16");
cell.addElement(p);
p = new Paragraph(32, "paragraph 2: leading 32");
cell.addElement(p);
p = new Paragraph(10, "paragraph 3: leading 10");
cell.addElement(p);
p = new Paragraph(18, "paragraph 4: leading 18");
cell.addElement(p);
p = new Paragraph(40, "paragraph 5: leading 40");
cell.addElement(p);

As you can see in leading_in_cell.pdf, you define the space between the lines using the first parameter of the Paragraph constructor. I've used different values to demonstrate how it works. The third paragraph sticks to the second one, because the leading of the third paragraph is only 10 pt. There's plenty of space between the fourth and the fifth paragraph, because the leading of the fifth paragraph is 40 pt.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165