MGDroid
MGDroid

Reputation: 1659

itext pdfpcell height in relation of 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 for A3 , A4 and A5 size pages. So I need a factor between Font size and Pdfpcell minimum height, so that the text can be visible. or is there any other way so that pdfpcell can shrink minimum in height so that the text may be visible?

Upvotes: 0

Views: 1495

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

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() method; 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.

Upvotes: 1

Related Questions