iText pdf library
Website search

How does a PdfPCell's height relate to the font size?

In iText, what is the minimum height of a PdfPCell for which a given size of font text is visible? I mean is there any ratio between PdfPCell and font size? I am making a PDF with pages of size A3, A4 and A5. I need to know the relation between Font size and PdfPCell minimum height, so that the text will be visible.

Posted on StackOverflow on Sep 3, 2013 by MGDroid

Different concepts are at play when adding text to a cell.

  • padding is the extra space inside the borders of the cell. It's similar to the concept with the same name in HTML. You can change the padding of a cell with the setPadding() method.
  • leading is the space between two lines. Even when there's only one line, this leading will be used to determine the baseline of the text. By default the leading is 1.5 times the font size. If you're working in text mode, the leading of a cell is set using the setLeading(); you can define a fixed leading (fixedLeading), or a leading that depends on the font size (multipliedLeading). This value is ignored if you're working in composite mode. In composite mode, the leading of the separate Elements added to the cell is used.
  • ascender and descender are two value that are font-specific. The ascender is a value that tells you how much space is needed above the baseline of the text; the descender is a value that tells you how much space is needed below the baseline of the text. You can tell iText to take these values into account with the methods setUseAscender() and setUseDescender().

So, if you want the cell to have a minimal size, you need to set the padding to 0, the leading to match the size of the font, and tell iText to use the ascender and descender value.

DISCLAIMER: in the past, we've received reports from customers that showed us that not all fonts contain the correct ascender and descender information. This needs to be fixed at the font level.

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