Hi Team,
Hi Priya,
I have observed the requirement shared by you and like to share that Aspose.Slides offer TextAutofitType property for text frame. You can set this property to Shape and when you do so, the shape height will be changed in accordance to added text. If you set the TextAutofitType.Normal, it will not change the shape size and change the font height to adjust the text in shape.
Also, the width and height of text frame is same as width and height of shape to which the text frame belongs to. I suggest you to please use the following sample code to serve the purpose.
public static void TextAutoFit()
{
StringBuilder Buffer = new StringBuilder();
String text = “Here is long text. This is long text. Long text, Long text, Long text, Here is long text. This is long text. Long text, Long text, Long text”;
Aspose.Slides.Presentation Pres = new Aspose.Slides.Presentation();
ISlide slide=Pres.Slides[0];
IAutoShape shape =slide.Shapes.AddAutoShape(ShapeType.Rectangle,100,100,200,200);
ITextFrame Holder=shape.AddTextFrame("");
Holder.TextFrameFormat.AutofitType=TextAutofitType.Normal;
IParagraph para = new Paragraph();
para.Text = text;
Holder.Paragraphs.Add(para);
if (shape.Y + shape.Height > Pres.SlideSize.Size.Height)
{
Console.WriteLine(“Text Overflowed from Slide”);
}
Pres.Save(“D:\Aspose Data\Test2.pptx”, SaveFormat.Pptx);
}
Many Thanks,
Hi,
I have used the below code block in my solution to check the shape height and based on condition i am moving the text to next slide. But here I am getting exception "Null Reference "for Shape Y property . Can someone please guide me where it went wrong and help me in resolving this issue.
IShape Shape = slide.Shapes[1];
if (Shape.Placeholder != null)
{
if (Shape.Placeholder.Type == PlaceholderType.Body || Shape.Placeholder.Type == PlaceholderType.Object)
{
Aspose.Slides.ITextFrame Holder = ((Aspose.Slides.IAutoShape)Shape).TextFrame;
Holder.TextFrameFormat.AutofitType = TextAutofitType.Shape;
if (Shape.Y + Shape.Height > presentation.SlideSize.Size.Height - 40)
{
overflow = true;
}
}
}v
Hi Priya,
I have observed the sample code share by you and there seems to be no issue. I request you to please provide the working sample project reproducing the issue along with source presentation. Before this, I request you to please try using Aspose.Slides for .NET 15.5.0 on your end as well first.
Many Thanks,