IRONSOFTWAREHOME
添加文本轮廓
using IronWord;
using IronWord.Models;

// Create new Word document
WordDocument doc = new WordDocument();

// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
    TextOutlineEffect = TextOutlineEffect.DefaultEffect,
};

// Create paragraph
Paragraph paragraph = new Paragraph();

// Create run with text and style
Run textRun = new Run(new TextContent("Hello World"));
textRun.Style = textStyle;

// Add run to paragraph
paragraph.AddChild(textRun);

// Add paragraph to document
doc.AddParagraph(paragraph);

// Export new Word document
doc.SaveAs("textOutlineEffect.docx");
Imports IronWord
Imports IronWord.Models

' Create new Word document
Dim doc As New WordDocument()

' Create and configure text style
Dim textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
    .TextOutlineEffect = TextOutlineEffect.DefaultEffect
}

' Create paragraph
Dim paragraph As New Paragraph()

' Create run with text and style
Dim textRun As New Run(New TextContent("Hello World"))
textRun.Style = textStyle

' Add run to paragraph
paragraph.AddChild(textRun)

' Add paragraph to document
doc.AddParagraph(paragraph)

' Export new Word document
doc.SaveAs("textOutlineEffect.docx")
NuGet Download
PM > Install-Package IronWord
添加文本轮廓

添加文本轮廓

添加文本轮廓效果

文本轮廓效果通过在每个字符周围绘制边框来增强文本的可见性和样式。 这种效果对于创建醒目、引人注目的文本,或者确保文本出现在图像或彩色背景上时的可读性尤其有用。 IronWord 提供TextOutlineEffect类,具有预设配置,可快速实施。

要应用文本轮廓,请创建一个TextEffect属性。 此预设提供了一个标准的轮廓配置,适用于大多数场景。 对于自定义轮廓,开发人员可以指定轮廓宽度、颜色和线条样式等属性,以实现特定的视觉效果。

设置文本样式后,创建一个包含所需Style属性。 使用AddChild将样式运行添加到段落中,然后将段落添加到文档中。 这种结构化的方法可以确保格式正确,并保持文档的完整性。

代码解释

using IronWord 为文本添加轮廓非常简单。 尽管文本轮廓很简单,但每个属性都可以进行调整以满足各种需求。 一旦导入了Word文档,通过将textStyle以包含文本轮廓效果。

要将此效果应用于文本,首先创建一个Run对象。 配置的Run,应用文本轮廓效果。 使用Paragraph添加到文档中。 这遵循文档层次结构:文档 → 段落 → 运行 → 文本内容。 最后,文档被导出。

使用 IronWord 了解更多关于文档元素的信息。
在 GitHub 上查看

准备开始了吗?

Nuget Downloads 56,401版本:2026.9刚刚发布

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户