How can i change the size of the shape to fit all of the text

I have the following code that create a rectangle and then sticks in some text. In certain cases, the text is longer than what fits into the size of the rectangle. Is there anyway to automatically resize the shape to fit all of the text (i don’t want to change text size)

var shapeId = roadmapSlide.Shapes.AddAutoShape(ShapeTypeEx.Rectangle, 35, 25, 80, 25);
ShapeEx shape = roadmapSlide.Shapes[shapeId];
shape.FillFormat.FillType = FillTypeEx.NoFill;
shape.FillFormat.SolidFillColor.Color = Color.FromArgb(198, 217, 241);

TextFrameEx textFrame = ((AutoShapeEx)shape).TextFrame;
ParagraphEx p = textFrame.Paragraphs[0];

PortionEx port = textFrame.Paragraphs[0].Portions[0];

port.PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
port.PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
port.PortionFormat.FontHeight = 7;
port.Text = “[” + project.Description + "] ";
port.PortionFormat.FontBold = NullableBool.True;
port.PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
port.PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
port.PortionFormat.FontHeight = 7;

shape.LineFormat.FillFormat.FillType = FillTypeEx.NoFill;

I see some old docs around some FitTextToShape() function (that i can’t find anyway) but i didn’t know if there was any FitShapeToText() function that existed that would either stretch the shape vertically or horizontally.

Hi Adam,

I have observed the requirements shared by you and suggest you to please try exploring TextFrameEx.AutofitType property for your convenience. Please share, if I may help you further in this regard.

Many Thanks,

Mudassir,

How does this work to resize the shape? Does it just change the height of the shape? Does it change the width?

Is there anyway to tell it to just change height or just change width (or choose some combination?

Hi Adam,

I have performed my testing using the following sample code. I have commented the line textFrame.AutofitType = TextAutofitTypeEx.Shape in one scenario and have generated two presentations. It is evident that when textFrame.AutofitType = TextAutofitTypeEx.Shape is used the shape gets resized to fit the text inside it and only grows vertically. There is no effect on the width. For your kind reference, I have attached the sample image, presentation files and sample code.

public static void TestFitShape()
{
PresentationEx pres = new PresentationEx();

SlideEx slide = pres.Slides[0];
var shapeId = slide.Shapes.AddAutoShape(ShapeTypeEx.Rectangle, 135, 125, 80, 25);
ShapeEx shape = slide.Shapes[shapeId];
shape.FillFormat.FillType = FillTypeEx.NoFill;
shape.FillFormat.SolidFillColor.Color = Color.FromArgb(198, 217, 241);

TextFrameEx textFrame = ((AutoShapeEx)shape).TextFrame;
// textFrame.AutofitType = TextAutofitTypeEx.Shape;

ParagraphEx p = textFrame.Paragraphs[0];

PortionEx port = textFrame.Paragraphs[0].Portions[0];
// textFrame.AutofitType = TextAutofitTypeEx.Shape;
port.PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
port.PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
port.PortionFormat.FontHeight = 7;
port.Text = “This is really long long text This is really long long text This is really long long text This is really long long text This is really long long text This is really long long text This is really long long text This is really long long text This is really long long text This is really long long text”; ;
port.PortionFormat.FontBold = NullableBool.True;
port.PortionFormat.FillFormat.FillType = FillTypeEx.Solid;
port.PortionFormat.FillFormat.SolidFillColor.Color = Color.Black;
port.PortionFormat.FontHeight = 7;

shape.LineFormat.FillFormat.FillType = FillTypeEx.NoFill;
pres.Write(“D:\Aspose Data\AutoShape2.pptx”);

}
Please share, if I may help you further in this regard.

Many Thanks,

Mudassir,

That sounds very restricting as, in my example, I would like to resize width (instead of height). The lack of the API to determine how it resizes seems very limiting. Is this going to be enhanced / fixed in a newer release?

Hi Adam,

I have observed your requirements and have created an issue with ID SLIDESNET-34598 as enhancement to investigate the possibility of implementing the support for autofitting shape in horizontal direction w.r.t text instead of vertical. This thread has been linked with the issue so that you may be automatically notified once the issue will be resolved.

We are sorry for your inconvenience,

Thanks Mudassir,


Please ensure that you can pass in both (not just one or the other). For example, maybe I want to expand 50% height and 50% width (or 80% width and 20% height)

Hi Adam,

I have observed the requirements shared and have appended them in our issue tracking system. We will consider them while resolving the specified issue as much as possible. We will share the feedback with you once the issue will be resolved.

Many Thanks,

How can I track SLIDESNET-34598 to see if the fix is supported in a newer version of aspose.slides? Should I expect to see an update on this forum thread or do i have to parse through every release notes?

Can I get an update on this issue please

Hi Adam,


I like to share that the access to our issue tracking system is restricted and only Aspose support and development teams have access to that. However, we do present the status of the issue in the very first post of the thread as attached in the image shared for our customers reference.

At present the issue is still pending and is not resolved. We will share the good news with you as soon as the issue will be resolved.

Many Thanks,

Is there any update to this old request given its been out there for a while? Are there any expectations that can be set for an enhancement to the API?

Hi,

I regret to share that at present the requested enhancement is unavailable in Aspose.Slides. However, I have raised the priority of the issue to high and have requested our product team to share the feedback in this regard. I will share further updates with you as soon as they will be shared by our product team.

We are sorry for your inconvenience,