如何在 C# 中为文本添加反射效果 | IronWord

How to Add Reflection Effect to Text

This article was translated from English: Does it need improvement?
Translated
View the article in English

A reflection effect on text is a visual enhancement that creates a mirror-like image of the text below its original form. This effect simulates the reflection of the text on a surface, often adding depth and realism to the design.

Quickstart: Apply Reflection Effect to Text in C#

With just one line of code using IronWord, you can apply a preset reflection effect to any text. Developers get up and running instantly—no complex setup or boilerplate code needed.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronWord with NuGet Package Manager

    PM > Install-Package IronWord

  2. Copy and run this code snippet.

    new IronWord.WordDocument().AddText("Quick Text").Style = new IronWord.Models.TextStyle(){ TextEffect = new IronWord.Models.TextEffect(){ ReflectionEffect = new IronWord.Models.Reflection() } };
  3. Deploy to test on your live environment

    Start using IronWord in your project today with a free trial
    arrow pointer

Add Reflection Effect

To specify the reflection effect for the text, create the TextStyle object and populate the ReflectionEffect property with a Reflection object. Finally, add new text with the style by assigning the TextStyle object to the TextEffect property.

:path=/static-assets/word/content-code-examples/how-to/text-effect-reflection-effect.cs
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()
{
    ReflectionEffect = new Reflection(),
};

// Add text with style
doc.AddText("Hello World").Style = textStyle;

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

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

' Create and configure text style
Private textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {.ReflectionEffect = New Reflection()}

' Add text with style
doc.AddText("Hello World").Style = textStyle

' Export new Word document
doc.SaveAs("reflectionEffect.docx")
$vbLabelText   $csharpLabel
Add reflection effect

Reflection Effect Properties

The reflection effect provides a range of adjustable attributes to meet diverse design requirements. See the following list for detailed descriptions of each property:

  • SchemeColor: Gets or sets the scheme color of the reflection effect.
  • HorizontalSkewAngle: Gets or sets the horizontal skew angle of the reflection effect. The skew angle is specified in degrees.
  • HorizontalScalingFactor: Gets or sets the horizontal scaling factor of the reflection effect.
  • DistanceFromText: Gets or sets the distance of the reflection effect from the text or object. The distance is specified in points (1/72 inch).
  • DirectionAngle: Gets or sets the direction angle of the reflection effect. The direction angle is specified in degrees.
  • FadeDirectionAngle: Gets or sets the fade direction of the reflection effect.
  • EndPosition: Gets or sets the ending position of the reflection effect.
  • StartPosition: Gets or sets the starting position of the reflection effect.
  • EndingOpacity: Gets or sets the ending opacity of the reflection effect.
  • VerticalScalingFactor: Gets or sets the vertical scaling factor of the reflection effect.
  • StartingOpacity: Gets or sets the starting opacity of the reflection effect.
  • Alignment: Gets or sets the alignment of the reflection effect.
  • BlurRadius: Gets or sets the blur radius of the reflection effect. The blur radius is specified in points (1/72 inch).
  • VerticalSkewAngle: Gets or sets the vertical skew angle of the reflection effect. The skew angle is specified in degrees.
:path=/static-assets/word/content-code-examples/how-to/text-effect-customized-reflection-effect.cs
using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;

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

// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
    ReflectionEffect = new Reflection()
    {
        Alignment = RectangleAlignmentValues.BottomLeft,
        BlurRadius = 5,
        DirectionAngle = 90,
        DistanceFromText = 5,
        EndingOpacity = 100,
        EndPosition = 10,
        FadeDirectionAngle = 90,
        HorizontalScalingFactor = 100,
        HorizontalSkewAngle = 0,
        SchemeColor = IronWord.Models.Color.Gold,
        StartingOpacity = 0,
        StartPosition = 0,
        VerticalScalingFactor = -100,
        VerticalSkewAngle = 0,
    },
};

// Add text with style
doc.AddText("Customized reflection").Style = textStyle;

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

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

' Create and configure text style
Private textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
	.ReflectionEffect = New Reflection() With {
		.Alignment = RectangleAlignmentValues.BottomLeft,
		.BlurRadius = 5,
		.DirectionAngle = 90,
		.DistanceFromText = 5,
		.EndingOpacity = 100,
		.EndPosition = 10,
		.FadeDirectionAngle = 90,
		.HorizontalScalingFactor = 100,
		.HorizontalSkewAngle = 0,
		.SchemeColor = IronWord.Models.Color.Gold,
		.StartingOpacity = 0,
		.StartPosition = 0,
		.VerticalScalingFactor = -100,
		.VerticalSkewAngle = 0
	}
}

' Add text with style
doc.AddText("Customized reflection").Style = textStyle

' Export new Word document
doc.SaveAs("customizedReflectionEffect.docx")
$vbLabelText   $csharpLabel
Customized reflection effect

常见问题解答

如何使用 C# 在 Word 文档中为文本添加反射效果?

你可以通过下载 IronWord 库使用 C# 在 Word 文档中添加反射效果。首先创建一个 `TextStyle` 对象,在 `ReflectionEffect` 属性中填入一个 `Reflection` 对象,并根据您的喜好自定义属性。最后,导出应用反射效果的 Word 文档。

在 IronWord 中,可以调节哪些反射效果的属性?

在 IronWord 中,您可以调整如 `SchemeColor`、`HorizontalSkewAngle`、`HorizontalScalingFactor`、`DistanceFromText`、`DirectionAngle`、`FadeDirectionAngle`、`EndPosition`、`StartPosition`、`EndingOpacity`、`VerticalScalingFactor`、`StartingOpacity`、`Alignment`、`BlurRadius` 和 `VerticalSkewAngle` 等属性,以自定义反射效果。

如何自定义反射效果与文本的距离?

在 IronWord 中,使用 `DistanceFromText` 属性来设置反射效果与文本的距离。该距离以点(1/72 英寸)为单位,允许您控制反射与原始文本之间的距离。

我可以在 IronWord 中调节反射效果的透明度吗?

可以,在 IronWord 中,反射效果的透明度可以通过 `StartingOpacity` 和 `EndingOpacity` 属性进行自定义。这些属性允许您定义反射的起始和结束透明度,为其视觉呈现提供控制。

`HorizontalSkewAngle` 在反射效果中有什么作用?

IronWord 中的 `HorizontalSkewAngle` 属性设置反射效果的水平倾斜角度。以度数指定,该属性通过水平倾斜来改变反射的外观。

如何开始在 C# 中为文本添加反射效果?

首先下载 IronWord 库。创建一个 `TextStyle` 对象,并在 `ReflectionEffect` 属性中填入一个 `Reflection` 对象。使用可用属性自定义效果并将其应用到文本中。

IronWord 中可以调整反射效果的模糊度吗?

可以,在 IronWord 中,您可以通过设置 `BlurRadius` 属性来调整反射效果的模糊度。此值以点(1/72 英寸)为单位,允许您控制反射的柔和度。

Curtis Chau
技术作家

Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。

除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。

准备开始了吗?
Nuget 下载 25,807 | 版本: 2025.11 刚刚发布