Free Support Forum -

How to get the alignment of Text Frame (C# .NET)

I didn’t get a property to get the alignment of text in TextFrame.
How can i get this
Please reply


Thanks for inquiring Aspose.Slides.

I like to share that you can set the text alignment for the selected paragraph text inside TextFrame. Please use the following code snippet to serve the purpose.

public static void AddTextFrame()
PresentationEx pres = new PresentationEx();
AutoShapeEx ashp = (AutoShapeEx)pres.Slides[0].Shapes[(pres.Slides[0].Shapes.AddAutoShape(ShapeTypeEx.Rectangle, 30, 30, 400, 400))];
TextFrameEx txt = ashp.TextFrame;
txt.Paragraphs[0].ParagraphFormat.Alignment = TextAlignmentEx.Right;
txt.Paragraphs[0].Portions[0].Text = “Hello World”;
pres.Write(“D:\Aspose Data\Align.pptx”);


Many Thanks,


Using latest version of Aspose.Slides, you can try using following sample code on your end to align the text inside text frame. Actually, the alignment of text is done on individual paragraph level inside text frame. The following example illustrates the usage of text alignment inside a text frame of a paragraph.

// Instantiate a Presentation object that represents a PPTX file
using (Presentation pres = new Presentation(dataDir + "ParagraphsAlignment.pptx"))

    // Accessing first slide
    ISlide slide = pres.Slides[0];

    // Accessing the first and second placeholder in the slide and typecasting it as AutoShape
    ITextFrame tf1 = ((IAutoShape)slide.Shapes[0]).TextFrame;
    ITextFrame tf2 = ((IAutoShape)slide.Shapes[1]).TextFrame;

    // Change the text in both placeholders
    tf1.Text = "Center Align by Aspose";
    tf2.Text = "Center Align by Aspose";

    // Getting the first paragraph of the placeholders
    IParagraph para1 = tf1.Paragraphs[0];
    IParagraph para2 = tf2.Paragraphs[0];

    // Aligning the text paragraph to center
    para1.ParagraphFormat.Alignment = TextAlignment.Center;
    para2.ParagraphFormat.Alignment = TextAlignment.Center;

    //Writing the presentation as a PPTX file
    pres.Save(dataDir + "Centeralign_out.pptx", SaveFormat.Pptx);