Adding Text to the Top Right and Top Left of a Slide Using Aspose.Slides for .NET 18.3

Hi everyone;

I opened this topic: How to Set Text to Header in Presentation Using Aspose.Slides for .NET 18.3 - Free Support Forum - aspose.com

When I was looking answer of this topic and try to something for getting what I want, I find AddAutoShape method of Aspose.Slides.

I try like that:

Presentation presentation = new Presentation(stream);
foreach(var slide in presentation.Slides)
{
    var shape = slide.AddAutoShape(Shape.Line, 0, 0, 300, 0);
    shape.AddTextFrame("Sample");
}

This code added something on left top corners of slides but letters top half couldn’t seem.

All of I need actually that. I need to text left top of corners and right top of corner all slides in presentation files programmatically. But I have to do it without broke slides.

I tried header and dateandtime but I couldn’t access them. I explain on my last reply in this issue : How to Set Text to Header in Presentation Using Aspose.Slides for .NET 18.3 - Free Support Forum - aspose.com

Anybody can show me a way, how can I insert text left and right top of corners of slides?

Thans a lot.

@hvkktr,
Thank you for posting the question.

To add text to the left and right top of corners of slides using Aspose.Slides for .NET 18.3 and the latest version, please use the following code example:

using (var presentation = new Presentation())
{
    var slideSize = presentation.SlideSize.Size;
    var slide = presentation.Slides[0];

    // Add text to the left-top corner.
    var autoShape1 = slide.Shapes.AddAutoShape(ShapeType.Rectangle, 0, 0, 100, 30);
    autoShape1.FillFormat.FillType = FillType.NoFill;
    autoShape1.LineFormat.FillFormat.FillType = FillType.NoFill;
    autoShape1.TextFrame.TextFrameFormat.AnchoringType = TextAnchorType.Top;
    autoShape1.AddTextFrame("Sample 1");

    // Format the text.
    var paragraph1 = autoShape1.TextFrame.Paragraphs[0];
    paragraph1.ParagraphFormat.Alignment = TextAlignment.Left;
    paragraph1.ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillType.Solid;
    paragraph1.ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Black;

    // Add text to the right-top corner.
    var autoShape2 = slide.Shapes.AddAutoShape(ShapeType.Rectangle, slideSize.Width - 100, 0, 100, 30);
    autoShape2.FillFormat.FillType = FillType.NoFill;
    autoShape2.LineFormat.FillFormat.FillType = FillType.NoFill;
    autoShape2.TextFrame.TextFrameFormat.AnchoringType = TextAnchorType.Top;
    autoShape2.AddTextFrame("Sample 2");

    // Format the text.
    var paragraph2 = autoShape2.TextFrame.Paragraphs[0];
    paragraph2.ParagraphFormat.Alignment = TextAlignment.Right;
    paragraph2.ParagraphFormat.DefaultPortionFormat.FillFormat.FillType = FillType.Solid;
    paragraph2.ParagraphFormat.DefaultPortionFormat.FillFormat.SolidFillColor.Color = Color.Black;

    presentation.Save("output.pptx", SaveFormat.Pptx);
}

Documents: Manage Text

1 Like

Thanks a lot. It worked.

@hvkktr,
Thank you for using Aspose.Slides.

1 Like