How do I calculate the width of the given string provided any specific font. I have text box in slide with given x width. I need to allow only certain number of characters in a string with width less than x.
For ex consider a string
This is a sample String to calculate width of text using Aspose method.
To calculate the width of a text string in a PowerPoint presentation, please try using the getRect() methods from the IParagraph and IPortion interfaces. I hope this will help you. Please let us know if you have any additional questions.
@andrey.potapov ,
Thanks for the reply.
I have to handle a use case in ppt where if the text width increases more than 665 I need to remove characters from end and add ellipsis (…). I need help to create substring based on the given text width and add ellipsis at the end so the final width is not more than 665.
I’m sharing a sample program with you where I have added a string with more than 665 width, here I have to remove few characters from end and add ellipsis so that the final text width is not greater than 665.
Could you help me here to create substring based on width of the string?
@VaradS,
Thank you for your patience. This cannot be done automatically. This is an algorithmic problem that you can solve, for example, using the bisection method:
You can calculate the width of the text string. If the width is too big, reduce the string by half. If half is too small, increase the string by half of the remaining length, and so on. When calculating the width of a substring, you also need to take into account the ellipsis.