We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Calc the Height of RichText for given width

Searching for possible API libs…

Is it possible to calc the height of a RichText String for a given width?

Somehting like:

CalcRichTextHeight(int given width)

Thx!

@adkaikaitode,

Unfortunately, your question is not clear enough therefore we request you to please elaborate your inquiry further by providing complete details of your usecase. Please ZIP and upload your sample Word document here for testing and also explain the requirement with the help of screenshot(s). This will help us to understand your scenario, and we will be in a better position to address your concerns accordingly.

test.zip (8.6 KB)

Here is my RTF Sample file. It has several lines and I need to know the height as float / int to set custom height of RichText Control to the given Document.

The Control has e.g. a width of 300px and for this rectangle the RTF Text should be shown and I need to know the boundaries (width and especially HEIGHT). Is that possible?

@adkaikaitode,

There are just four Paragraphs in your provided RTF file and no control. Can you please also provide a screenshot highlighting the area you want to calculate the height of? In this case, what is the expected height that Aspose.Words should return? Thanks for your cooperation.

Yes sure, here is an explanatory screenshot attached.
I want just the height of the text area as return value.
Thanks!7eVAQT0Oik.png (5.6 KB)

@adkaikaitode,

You can build on the following code to get the height of selected area:

Document doc = new Document("E:\\test\\test.rtf");

LayoutCollector layoutCollector = new LayoutCollector(doc);
LayoutEnumerator layoutEnumerator = new LayoutEnumerator(doc);

layoutEnumerator.Current = layoutCollector.GetEntity(doc.FirstSection.Body.FirstParagraph);
float top = layoutEnumerator.Rectangle.Top;

layoutEnumerator.Current = layoutCollector.GetEntity(doc.FirstSection.Body.LastParagraph);
float bottom = layoutEnumerator.Rectangle.Bottom;

Console.WriteLine("Height is {0} points. And 72 points equal 1 inch.", bottom - top); 

Hope, this helps.