How to adjust font size to fill fixed-height cells in iTextSharp

I am creating a PDF from iTextSharp for printing. I have text of variable length that I would like to always have the maximum font size to fill a cell of a table with a fixed height without closing it out of sight. How can I do that?

+3
source share
1 answer

You need to start by saying that you can measure the width of the text in the font of your choice. From the iTextSharp documentation:

Measuring text

. BaseFont, : public float getWidthPoint ( , float ); , - 36, , -, : getWidthPoint ( "0123456789", 36f). . 72 1 . 252 ( 8), : 252 /72 = 3,5 * 2,54 = 8,89 .

, . , , .

textWidth = getWidthPoint("sample text", originalFontHeight)
newFontHeight = (cellWidth / textWidth ) * originalFontHeight

, ( ) .

+6

Source: https://habr.com/ru/post/1728947/


All Articles