Also, remember, Presentation.Slides collection contains both normal and master slide. So don’t use it to get reference to normal slide, instead use Presentation.GetSlideByPosition method.
e.g
// slide 0 is the template page
Slide slide = pres.GetSlideByPosition(1);// slide position starts from 1
Below is the sample code that adds a rectangle, then add text inside it and fit the text to shape.
Presentation srcPres = new Presentation();
Slide srcSld = srcPres.GetSlideByPosition(1);
Shape shp = srcSld.Shapes.AddRectangle(100, 100, 3000, 1000);
//shp.LineFormat.ShowLines = false;
TextFrame tf = shp.AddTextFrame("");
tf.WrapText = true;
tf.Text = "This is lot of text, this is lot of text, this is lot of text, this is lot of text, this is lot of text, this is lot of text, this is lot of text, this is lot of text, this is lot of text, this is lot of text, this is lot of text, this is lot of text, this is lot of text, this is lot of text, this is lot of text, this is lot of text, this is lot of text, this is lot of text, this is lot of text, this is lot of text.";
tf.FitTextToShape();
srcPres.Write("c:\\outFitText.ppt");
However, I would like to read an existing TextFrame in my slide. I've modified my code but the text doesn't fit into the the rectangle. I've attached a sample powerpoint.
Well, I found, it is working fine. I am using Aspose.Slides 2.7.3.0 for .NET. Please see the attached ppts generated by the code below without and without FitTextToShape.
txtFrameBody.Text = "This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.This is text.";