Is there a way to calculate the required width of a TextArea with kerning enabled?
For single-lined textareas I found out I could use
.GetLineTextWidth(0)
Is there a way for achieving the same for multilined?
.GetTextWidth and kerning
Re: .GetTextWidth and kerning
Support · Oct 2, 2013Hello,
You can use the GetVisibleLineCount() method to retireve the number of lines in the text area and get the line width for each line. Here is the sample code.
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
string text = "this is a text area with text ";
text += text;
text += text;
text += text;
text += text;
text += text;
TextArea textArea = new TextArea(text, 100, 100, 400, 400, ceTe.DynamicPDF.Font.Helvetica, 12);
textArea.KerningEnabled = true;
KerningValues kernValues = textArea.GetKerningValues();
int lineCount = textArea.GetVisibleLineCount();
for (int i = 1; i <= lineCount; i++)
{
float lineWidth = textArea.GetLineTextWidth(i);
}
page.Elements.Add(textArea);
document.Draw("output.pdf");
Thanks,
ceTe Software Support Team.