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

Free Support Forum - aspose.com

Incorrect paragraph ending in Shape TextBox


I’ve run into an issue when a Shape(tried it on Oval and Rect) with specified height and width has a text box inside it with FitShapeToText set to true and the contents of the textbox stretch the shape. In this case the paragraph of the TextBox seems to end where it would if it had the specified height, but the shape is actually larger due to the contents of the TextBox stretching it. I’ve attached sample code that causes the issue. When I slightly resize the shape in the document or change the wrap text settings in word the document renders correctly.

var documentBuilder = new DocumentBuilder();

var shape = new Shape(documentBuilder.Document, ShapeType.Ellipse)
    WrapType = WrapType.Inline,
    TextBox = { FitShapeToText = true },
    StrokeColor = Color.Black,
    Height = 200,
    Width = 100
var paragraph = new Paragraph(documentBuilder.Document);
var longText = new string('a', 300);
paragraph.AppendChild(new Run(documentBuilder.Document, longText));

var paragraphBelow =
    new Paragraph(documentBuilder.Document).AppendChild(new Run(documentBuilder.Document, "Text below shape Text below shape Text below shape"));


Could you take a look?

Thank you,

@acturisaspose Can you attach a document with the expected output or a screenshot pointing out your problem? I have been testing your code and found nothing out of place, I also replicated it with MS Word application and get the same result.


I’ve attached the expected result to this message. As you can seen the text should be at the bottom. As stated above, it also goes all the way to the bottom when I even slightly resize the shape in the rendered document or when I change the wrap text settings to Inline(and it is set to inline in the code already).

ExpectedOutput.docx (23.7 KB)


@acturisaspose in my output the text “Text below shape Text below shape Text below shape” is aligned with the bottom part of the shape (I’m using version 23.3 of Aspose.Words to test). Can you share with me your current output?
output.docx (7.0 KB)

Attaching the output here:

ExampleOutput.docx (17.5 KB)

output.PNG (27.8 KB)

I tested it on versions 22.8 and 23.1

@acturisaspose what version of MS Word are you using to visualize the document? Because that seems to be the cause. When I open your document the text is placed at the middle of the shape, but after less than a second MS Word realign it with the bottom of the shape. (I’m using Microsoft® Word for Microsoft 365 MSO (Version 2301 Build 16.0.16026.20196) 64-bit)

Initially I used Word 2016. Now I tried it in Word 2019 and when I open the document it is exactly as you described - misaligned for about 1 second and then aligned properly. But after enabling editing it goes back to the middle of the shape and stays there.

@acturisaspose I tried using the same versions of MS Word that you mention and got the same result, unfortunately this is out of scope of Aspose.Words API, because the API is setting the right values, also for the last version of Word app in Office 365, the behavior is the expected.


sorry for the late reply. In my example if you check the height of the shape right before saving the document it is set to 200, which is the height set initially, but the actual height of the shape is actually larger due to the content of the shape stretching it. Is this the correct value? I’d also like to ask if there is some property in the Shape class that contains the actual height of the rendered shape, so maybe we could manually assign this value to height and workaround it that way.


@acturisaspose the height that you see in MS Word is calculated during the render process. So the measures of the Shape are what you set and see using Aspose.Words API, but MS Word recalculate it when the Shape is displayed.
The use of LayoutCollector and LayoutEnumerator simulates the MS Word render process.