Posted by a ceTe Software moderator
Hello,
Yes, you can calculate the text width and set this value to Label without any problem using our DynamicPDF Generator for .NET API. You will need to use the Font class members to do this. You can get the text width using GetTextWidth method of Font class which takes text, font size as arguments. Please refer to the documentation on Font class members
here. Also please make sure of setting same font and font size for the Label page element. Below is the sample code for it.
Document docuemnt = new Document();
Page page = new Page();
docuemnt.Pages.Add(page);
string text = "This is for calculating text width";
Font font = Font.Helvetica;
float textwidth = font.GetTextWidth(text, 12);
Label label = new Label(text, 100, 100, textwidth, 30, font,12);
page.Elements.Add(label);
Rectangle rect = new Rectangle(100, 100, textwidth, 30);
page.Elements.Add(rect);
docuemnt.Draw(@"C:\Temp\MyDocument.pdf");
Thanks,
ceTe Software Support Team.