Posted by a ceTe Software moderator
Hello,
You can get the character width by using the GetGlyphWidth method of the Font class. You will have to add the width's of all the characters to font out the X position for the link. The width returned by this method is in short and you will have to convert it into float. Following is some sample code for this.
Document doc = new Document();
Page page = new Page();
string str = "ceTe Software Support Team";
Label label = new Label(str, 0, 10, 500, 20, Font.Helvetica, 12);
//Split using the " " space character to find the last word
string[] array = str.Split(new char[]{' '});
string last = array.GetValue(array.Length - 1).ToString();
float tot1 = 0;
float tot2 = 0;
//Find the total width of the string
for(int i=0; i<str.Length - 1; i++)
{
tot1 += Font.Helvetica.GetGlyphWidth(str[i]);
}
//Width of the last word
for(int i=0; i<last.Length - 1; i++)
{
tot2 += Font.Helvetica.GetGlyphWidth(last[i]);
}
//Subtract the width of the last word from the total width
tot1 = tot1 - tot2;
UrlAction act = new UrlAction(@"http://www.DynamicPDF.com");
//width*fontsize/1000+0.001f , this is used to convert the width into float value
Link lnk = new Link(tot1*12/1000+0.001f, 10, Font.Helvetica.GetTextWidth(last, 12), 20, act);
page.Elements.Add(label);
page.Elements.Add(lnk);
doc.Pages.Add(page);
doc.DrawToWeb();
Thanks,
ceTe Software Support Team.