How do I get the font size that fits into the cell?

The font size is too large in the order shown below.
So when I call Document.Save(), it get stuck in infinite loop.
Is there a way for Text width to find the perfect font size for cell width?

TextState textState = new TextState(“Courier”, true, false);
float fontSize = textState.FontSize;

while (textState.MeasureString(“Some Text”) < Table.GetWidth())
{
fontSize = fontSize + 0.2f;

textState.FontSize = fontSize;

}

@Junyoung,

You can get the width of text before adding to the table’s cell as follows:
C#

TextFragment textFragment = new TextFragment("Some text there");
// Set text properties
textFragment.TextState.FontSize = 12;
textFragment.TextState.Font = FontRepository.FindFont("Courier");
double width = textFragment.Rectangle.Width;