News Category

Apply Transparency to Text in PowerPoint in C#, VB.NET

2017-12-07 08:44:21 Written by  jie zou
Rate this item
(0 votes)

It is possible to add text transparency to any text shape in PowerPoint. In order to make the text transparent, we’d need to apply the transparency level to the text shape. This article will show you how to set the transparency level of text using Spire.Presentation.

Step 1: Create a Presentation instance.

Presentation ppt = new Presentation();

Step 2: Add a shape to the first slide.

IAutoShape textboxShape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70,300, 120));
textboxShape.ShapeStyle.LineColor.Color = Color.Transparent;
textboxShape.Fill.FillType = FillFormatType.None;

Step 3: Add text to shape.

textboxShape.TextFrame.Text = "Text Transparency";

Step 4: Set the fill type of TextRange to solid, and fill the TextRange using the color created with specified alpha value.

textboxShape.TextFrame.TextRange.Fill.FillType = FillFormatType.Solid;
int alpha = 55;
textboxShape.TextFrame.TextRange.Fill.SolidColor.Color = Color.FromArgb(alpha, Color.Purple);

Step 5:Save the file.

ppt.SaveToFile("result.pptx", FileFormat.Pptx2013);

Output:

Apply Transparency to Text in PowerPoint in C#, VB.NET

Full Code:

[C#]
using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace ApplyTransparency
{
    class Program
    {
        static void Main(string[] args)
        {

            //create a PowerPoint document
            Presentation ppt = new Presentation();
            ppt.SlideSize.Type = SlideSizeType.Screen16x9;

            //add a shape
            IAutoShape textboxShape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 300, 120));
            textboxShape.ShapeStyle.LineColor.Color = Color.Transparent;
            textboxShape.Fill.FillType = FillFormatType.None;

            //remove default blank paragraphs
            textboxShape.TextFrame.Paragraphs.Clear();

            //add three paragraphs, apply color with different alpha values to text
            int alpha = 55;
            for (int i = 0; i < 3; i++)
            {
                textboxShape.TextFrame.Paragraphs.Append(new TextParagraph());
                textboxShape.TextFrame.Paragraphs[i].TextRanges.Append(new TextRange("Text Transparency"));
                textboxShape.TextFrame.Paragraphs[i].TextRanges[0].Fill.FillType = FillFormatType.Solid;
                textboxShape.TextFrame.Paragraphs[i].TextRanges[0].Fill.SolidColor.Color = Color.FromArgb(alpha, Color.Purple);
                alpha += 100;
            }

            //save to file
            ppt.SaveToFile("result.pptx", FileFormat.Pptx2013); 

        }
    }
}
[VB.NET]
Imports Spire.Presentation
Imports Spire.Presentation.Drawing
Imports System.Drawing
Namespace ApplyTransparency
	Class Program
		Private Shared Sub Main(args As String())

			'create a PowerPoint document
			Dim ppt As New Presentation()
			ppt.SlideSize.Type = SlideSizeType.Screen16x9

			'add a shape
			Dim textboxShape As IAutoShape = ppt.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(50, 70, 300, 120))
			textboxShape.ShapeStyle.LineColor.Color = Color.Transparent
			textboxShape.Fill.FillType = FillFormatType.None

			'remove default blank paragraphs
			textboxShape.TextFrame.Paragraphs.Clear()

			'add three paragraphs, apply color with different alpha values to text
			Dim alpha As Integer = 55
			For i As Integer = 0 To 2
				textboxShape.TextFrame.Paragraphs.Append(New TextParagraph())
				textboxShape.TextFrame.Paragraphs(i).TextRanges.Append(New TextRange("Text Transparency"))
				textboxShape.TextFrame.Paragraphs(i).TextRanges(0).Fill.FillType = FillFormatType.Solid
				textboxShape.TextFrame.Paragraphs(i).TextRanges(0).Fill.SolidColor.Color = Color.FromArgb(alpha, Color.Purple)
				alpha += 100
			Next

			'save to file
			ppt.SaveToFile("result.pptx", FileFormat.Pptx2013)

		End Sub
	End Class
End Namespace

Additional Info

  • tutorial_title:
Last modified on Friday, 24 September 2021 09:17