Calculate Font Size to fit into Text Area

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v7)  /  Calculate Font Size to fit into Text Area

DynamicPDF CoreSuite for .NET (v7) Forum

2 questions:

1. I have some TextAreas in my report that need to be a consistent size and I need to calculate what font size to use to fit the variable text in those TextAreas. I was able to do this for TextAreas that are a single line (using OpenTypeFont.GetTextWidth) but I am not sure how to calculate this when I allow vertical space for multiple lines. Is there a way to calculate the needed font size to fit text into a specified TextArea's height/width?

2. When I change the font size of an OpenTypeFont for a TextArea, the text is vertically aligned to the top of the area. How can I calculate my x,y plotting to compensate for the font height to have a smaller font justified to the baseline (or bottom) of the planned area?

Thanks
Posted by a ceTe Software moderator
Hello,

For TextArea with multiple lines, you can check the height it would need by calling the GetRequiredHeight() method. Here is the documentation link. Based on the required height value  you can adjust the font size to make it fit the specified verticle space.

The default value of VAlign property is top so the text is getting aligned to the top of the TextArea. If you know the x, y co-ordinates of where the desired area starts, set the TextArea’s x, y co-ordiantes to that of the desired area co-ordiantes and set the TextArea’s Height property to the vertical height of the desired area and set the TextArea.VAlign to bottom.

If these suggestions does not satisfy your requirements, feel free to email the code and output PDF to support@cete.com so we can look into it further.

Thanks,
ceTe Software Support Team.
Thanks, I think that will work

All times are US Eastern Standard time. The time now is 9:31 PM.