Trim excess text for TextFrame

I want to trim a text if the text is longer than the space of the shape and place a “…” at the end to indicate that there were text that were trimmed.

I tried fixing the length of my height and set the AutoFitType to None and NotDefined but I am not having any luck. The text still overflows outside the shape.

Is this possible in the current version of Aspose slides?

I also saw this post but the last reply was still in 2008.

Hi Wahoho,

Thank you for your interest in Aspose.Slides.

I have observed your comments and worked over your requirements. I request you to please try using following sample code on your end to serve the purpose.

Presentation pres = new Presentation();

//Get the first slide
ISlide sld = pres.Slides[0];

//Add an AutoShape of Rectangle type
IAutoShape ashp = sld.Shapes.AddAutoShape(ShapeType.Rectangle, 150, 75, 150, 50);

//Add TextFrame to the Rectangle
ashp.AddTextFrame(" ");

//Accessing the text frame
ITextFrame txtFrame = ashp.TextFrame;

//Create the Paragraph object for text frame
IParagraph para = txtFrame.Paragraphs[0];

//Create Portion object for paragraph
IPortion portion = para.Portions[0];

//Set Text
portion.Text = "Aspose TextBox1234";

if ((portion.Text.Length * 10) > ashp.Width)
{
    String str = portion.Text.Remove(portion.Text.Length - 3);
    MessageBox.Show(str);
    portion.Text = str + "...";
}

//Save the presentation to disk
pres.Save(@"D:\Test.pptx", SaveFormat.Pptx);

In the code above; a constant number 10 is being multiplied, which you may change as per your requirements.

I hope this will be helpful. Please share if I may help you further on this regard.

Best Regards,