iText pdf library
Website search

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

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

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

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.

Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now