How to Set Font of Text in PowerPoint

PPT file format is commonly used for office and educational slide shows. With Spire.Presentation, you can generate beautiful and powerful PPT files and edit them without utilizing Microsoft PowerPoint. The PPT files generated are compatible with PowerPoint.

In this document, I will introduce you how to set Font of text in PPT file. First add IAutoShape to the slide. The IAutoShape is a TextBox. You have to add it first. Then add text to the IAutoShape using the method AppendTextFrame. Then you can get the property TextRange of the shape. Using TextRange, you can set Font of text finally.

Step 1: Add the shape to the slide.

IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle,
                new RectangleF(50, 70, 400, 50));

Step 2: Add the text to the shape.

shape.AppendTextFrame("This is a demo of text font and color.");

Step 3: Get the property TextRange of the text.

TextRange textRange = shape.TextFrame.TextRange;

Step 4: Set the Font of the text in shape.

textRange.FontHeight = 21;
textRange.IsItalic = TriState.True;
textRange.TextUnderlineType = TextUnderlineType.Single;
textRange.LatinFont = new TextFont("Gulim");

Step 5: Save the document.

presentation.SaveToFile("text.pptx", FileFormat.Pptx2007);

Full code:

//create PPT document
Presentation presentation = new Presentation();

//set background Image
string ImageFile = @"..\..\..\..\..\..\Data\bg.png";
RectangleF rect = new RectangleF(0, 0, presentation.SlideSize.Size.Width, presentation.SlideSize.Size.Height);
presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile, rect);
presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;

//append new shape
IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle,
    new RectangleF(50, 70, 400, 50));

//set the LineColor
shape.ShapeStyle.LineColor.Color = Color.Black;

//set the color and fill style
shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
shape.Fill.SolidColor.Color = Color.LightGray;
shape.AppendTextFrame("This is a demo of text font and color.");

//set the color of text in shape
TextRange textRange = shape.TextFrame.TextRange;
textRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
textRange.Fill.SolidColor.Color = Color.Green;
            
//set the Font of text in shape
textRange.FontHeight = 21;
textRange.IsItalic = TriState.True;
textRange.TextUnderlineType = TextUnderlineType.Single;
textRange.LatinFont = new TextFont("Gulim");

//save the document
presentation.SaveToFile("text.pptx", FileFormat.Pptx2007);
System.Diagnostics.Process.Start("text.pptx");

Screenshot:

How to Set Font of Text in PPT