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

Free Support Forum - aspose.com

How to get the changed height of textbox in case of content overflow

Hi there,

I am creating a TextBox on a Slide dynamically using below code and adding text to it later. I want to get the changed height of textbox in case of content overflow but height of shape remains same(it’s 30 in my code below) even when text is spilling out of shape(textbox).

Please help. How can i achieve the above stated? Is there any other way to achieve this without using template based approach?


Code:

//Instantiate PresentationEx//Instantiate PresentationEx
using (Presentation pres = new Presentation())
{
<span class="code-comment" style="color: rgb(128, 128, 128); background-color: inherit;">//Get the first slide

ISlide sld = pres.Slides[0];

<span class="code-comment" style="color: rgb(128, 128, 128); background-color: inherit;">//Add an AutoShape of Rectangle type

IAutoShape ashp = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 30, 100, 600, 30);

<span class="code-comment" style="color: rgb(128, 128, 128); background-color: inherit;">//Add TextFrame to the Rectangle

ashp.AddTextFrame(" ");

<span class="code-comment" style="color: rgb(128, 128, 128); background-color: inherit;">//Accessing the text frame

ITextFrame txtFrame = ashp.TextFrame;

<span class="code-comment" style="color: rgb(128, 128, 128); background-color: inherit;">//Create the Paragraph object <span class="code-keyword" style="color: rgb(0, 0, 145); background-color: inherit;">for</span> text frame

IParagraph para = txtFrame.Paragraphs[0];

<span class="code-comment" style="color: rgb(128, 128, 128); background-color: inherit;">//Create Portion object <span class="code-keyword" style="color: rgb(0, 0, 145); background-color: inherit;">for</span> paragraph

IPortion portion = para.Portions[0];

<span class="code-comment" style="color: rgb(128, 128, 128); background-color: inherit;">//Set Text

portion.Text = “Electricite de France SA (EDF) is a France-based electricity producer, marketer and distributor. The company generates energy using nuclear technology, as well as thermal, hydroelectric and other renewable energy sources. EDF also manages low- and medium-voltage public distribution networks and is involved in electricity transmission networks.”
+" Electricite de France SA (EDF) is a France-based electricity producer, marketer and distributor. The company generates energy using nuclear technology, as well as thermal, hydroelectric and other renewable energy sources. EDF also manages low- and medium-voltage public distribution networks and is involved in electricity transmission networks."
+ " Electricite de France SA (EDF) is a France-based electricity producer, marketer and distributor. The company generates energy using nuclear technology, as well as thermal, hydroelectric and other renewable energy sources. EDF also manages low- and medium-voltage public distribution networks and is involved in electricity transmission networks.";

// height of shape remains same(it’s 30) even when text is spilling out of shape(textbox).
float shapeHeightAfterAddingText = ashp.Height;

//Save the presentation to disk
pres.Save(“TextBox.pptx”, SaveFormat.Pptx);
}


Hi Pradeep,

I have observed the sample code shared by you and suggest you to please add the following code line before adding text in portion.

txtFrame.TextFrameFormat.AutofitType=TextAutofitType.Shape;

Actually, by default the TextAutofitType is set to Normal and text gets fitted into shape by height alteration. Once the above property will be set, you will be able to observe the shape height.

Many Thanks,