I was creating a C# Console Application that fills in the details in a certificate template (pdf) file using ITextSharp. The text that needs to be filled is dynamically generated.
If the dynamically generated text exceeds a certain size the field name gets truncated. I have already thought of an algorithm to solve this problem for which I require the maximum number of characters that can be accommodated in a page with the given font and font-size. The width of the page where the text has to be accommodated is given to us already.
I used the following code:
string text = "This is the test string that needs to be accommodated";
// Registering a font
FontFactory.Register("somefont.ttf", "script");
var script = FontFactory.GetFont("script", 20f); // registers the font with the given type and size.
Phrase phrase_text = new Phrase();
phrase_text.Add(new Chunk(text, script));
ColumnText.ShowTextAligned(pbover, Element.ALIGN_CENTER, new Phrase(phrase_text), PageSize.A4.Height/2, 140, 0);
This code seems to work fine, but when I am adding a bigger text in the screen, the text gets truncated with the alignment still in the center (in the horizontal sense).
I was reading something on using the Graphics library, but could not resolve the issue.