Spire.Presentation支持为幻灯片中的文本添加带有颜色的文本边框,让文字显示的时候可以拥有描边效果,这样幻灯片中的文字会更美观。该文将详细介绍如何使用Spire.Presentation为幻灯片中的文字添加文本边框。
在Microsoft PowerPoint中,选中幻灯片中的shape后,右键“设置文字效果格式”,然后在文本选项中可以看到文本边框,通过设置边框线条样式,颜色,宽度等属性对文本设置描边效果。请查看文字添加了文本边框后的效果图:
Spire.Presentation如何设置文本选项下的文本边框
C#
//新建一个PowerPoint文档
Presentation ppt = new Presentation();
//设置幻灯片大小和方向
ppt.SlideSize.Type = SlideSizeType.Screen16x9;
ppt.SlideSize.Orientation = SlideOrienation.Landscape;
//设置幻灯片背景填充颜色
ppt.Slides[0].SlideBackground.Type = BackgroundType.Custom;
ppt.Slides[0].SlideBackground.Fill.FillType = FillFormatType.Solid;
ppt.Slides[0].SlideBackground.Fill.SolidColor.Color = Color.DarkSeaGreen;
//添加一个shape到第一张幻灯片
IAutoShape textboxShape = ppt.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(50, 70, 700, 100));
textboxShape.ShapeStyle.LineColor.Color = Color.Transparent;
textboxShape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None;
//清除shape上的段落(默认有一个空白段落)
textboxShape.TextFrame.Paragraphs.Clear();
//在shape上添加段落并写入文本
textboxShape.TextFrame.Paragraphs.Append(new TextParagraph());
textboxShape.TextFrame.Paragraphs[0].TextRanges.Append(new TextRange("Spire.Presentation for .NET"));
textboxShape.TextFrame.Paragraphs[0].SpaceAfter = 50f;
textboxShape.TextFrame.Paragraphs.Append(new TextParagraph());
string text = "C#设置幻灯片文本边框";
textboxShape.TextFrame.Paragraphs[1].TextRanges.Append(new TextRange(text));
//设置段落中文字的字体、大小、颜色,并设置文本边框的填充颜色和宽度
foreach (TextParagraph para in textboxShape.TextFrame.Paragraphs)
{
para.TextRanges[0].LatinFont = new TextFont("Arial Rounded MT Bold");
para.TextRanges[0].FontHeight = 40f;
para.TextRanges[0].Fill.FillType = FillFormatType.Solid;
para.TextRanges[0].Fill.SolidColor.Color = Color.Black;
para.TextRanges[0].TextLineFormat.FillFormat.FillType = FillFormatType.Solid;
para.TextRanges[0].TextLineFormat.FillFormat.SolidFillColor.Color = Color.White;
para.TextRanges[0].TextLineFormat.Width = 1.52f;
}
//保存文档
ppt.SaveToFile("Result.pptx", FileFormat.Pptx2013);
VB.NET
'新建一个PowerPoint文档
Dim ppt As New Presentation()
'设置幻灯片大小和方向
ppt.SlideSize.Type = SlideSizeType.Screen16x9
ppt.SlideSize.Orientation = SlideOrienation.Landscape
'设置幻灯片背景填充颜色
ppt.Slides(0).SlideBackground.Type = BackgroundType.[Custom]
ppt.Slides(0).SlideBackground.Fill.FillType = FillFormatType.Solid
ppt.Slides(0).SlideBackground.Fill.SolidColor.Color = Color.DarkSeaGreen
'添加一个shape到第一张幻灯片
Dim textboxShape As IAutoShape = ppt.Slides(0).Shapes.AppendShape(ShapeType.Rectangle, New RectangleF(50, 70, 700, 100))
textboxShape.ShapeStyle.LineColor.Color = Color.Transparent
textboxShape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.None
'清除shape上的段落(默认有一个空白段落)
textboxShape.TextFrame.Paragraphs.Clear()
'在shape上添加段落并写入文本
textboxShape.TextFrame.Paragraphs.Append(New TextParagraph())
textboxShape.TextFrame.Paragraphs(0).TextRanges.Append(New TextRange("Spire.Presentation for .NET"))
textboxShape.TextFrame.Paragraphs(0).SpaceAfter = 50F
textboxShape.TextFrame.Paragraphs.Append(New TextParagraph())
Dim text As String = "C#设置幻灯片文本边框"
textboxShape.TextFrame.Paragraphs(1).TextRanges.Append(New TextRange(text))
'设置段落中文字的字体、大小、颜色,并设置文本边框的填充颜色和宽度
For Each para As TextParagraph In textboxShape.TextFrame.Paragraphs
para.TextRanges(0).LatinFont = New TextFont("Arial Rounded MT Bold")
para.TextRanges(0).FontHeight = 40F
para.TextRanges(0).Fill.FillType = FillFormatType.Solid
para.TextRanges(0).Fill.SolidColor.Color = Color.Black
para.TextRanges(0).TextLineFormat.FillFormat.FillType = FillFormatType.Solid
para.TextRanges(0).TextLineFormat.FillFormat.SolidFillColor.Color = Color.White
para.TextRanges(0).TextLineFormat.Width = 1.52F
Next
'保存文档
ppt.SaveToFile("Result.pptx", FileFormat.Pptx2013)