Skip to main content
Skip table of contents

How to define spacing and leading in PdfPCell objects?

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.

 

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);
Posted on StackOverflow on Nov 22, 2013 by Micael Florêncio

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

Cell cell = new Cell();
Paragraph p;
p = new Paragraph("paragraph 1: leading 16. Text to force a wrap and check the leading. Ha-ha").setFixedLeading(16);
cell.add(p);
p = new Paragraph("paragraph 2: leading 32. Text to force a wrap and check the leading. Ha-ha").setFixedLeading(32);
cell.add(p);
p = new Paragraph("paragraph 3: leading 10. Text to force a wrap and check the leading. Ha-ha").setFixedLeading(10);
cell.add(p);
p = new Paragraph("paragraph 4: leading 18. Text to force a wrap and check the leading. Ha-ha").setFixedLeading(18);
cell.add(p);
p = new Paragraph("paragraph 5: leading 40. Text to force a wrap and check the leading. Ha-ha").setFixedLeading(40);
cell.add(p);

As you can see in the resulting pdf, you define the space between the lines using the setFixedLeading() method. 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.

Click How to define spacing and leading in PdfPCell objects? if you want to see how to answer this question in iText 5.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.