How to Add Text Outline Effect to Text
A text outline effect adds a visible border around the characters of text, creating a defined outline that enhances readability or visual impact. This effect can be customized in terms of color, thickness, and style to suit design preferences. It's commonly used in graphics, typography, and digital design to make text stand out against backgrounds or to create a stylized appearance.
Get started with IronWord
Start using IronWord in your project today with a free trial.
How to Add Text Outline Effect to Text
- Download a C# library to add a text outline to text
- Apply the text effect to either newly created or existing text
- Apply a preset text outline effect using the static named instance of the TextOutlineEffect class
- Configure the TextOutlineEffect properties to achieve a customized text outline
- Export the edited Word document as a new file
Add Text Outline Effect
To specify the text outline effect for the text, create the TextStyle object and populate the TextOutlineEffect property with a TextOutlineEffect 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-text-outline-effect.cs
// This is the source code to create a Word document and add text with a style effect using IronWord.
// Necessary using directives are included for the IronWord library.
using IronWord;
using IronWord.Models;
// Create a new Word document.
WordDocument doc = new WordDocument();
// Create and configure a text style.
// TextStyle allows customization of text effects such as outline, shadow, etc.
TextStyle textStyle = new TextStyle
{
TextEffect = new TextEffect
{
// Set the text outline effect.
// DefaultEffect is a predefined effect; you can modify or use other available effects as needed.
TextOutlineEffect = TextOutlineEffect.DefaultEffect
}
};
// Add text to the document with the specified style.
// The Style property of the added text is set to the custom textStyle defined above.
doc.AddText("Hello World").Style = textStyle;
// Save the newly created Word document to a file.
// "textOutlineEffect.docx" is the name of the output file where the document will be saved.
doc.SaveAs("textOutlineEffect.docx");
' This is the source code to create a Word document and add text with a style effect using IronWord.
' Necessary using directives are included for the IronWord library.
Imports IronWord
Imports IronWord.Models
' Create a new Word document.
Private doc As New WordDocument()
' Create and configure a text style.
' TextStyle allows customization of text effects such as outline, shadow, etc.
Private textStyle As New TextStyle With {
.TextEffect = New TextEffect With {.TextOutlineEffect = TextOutlineEffect.DefaultEffect}
}
' Add text to the document with the specified style.
' The Style property of the added text is set to the custom textStyle defined above.
doc.AddText("Hello World").Style = textStyle
' Save the newly created Word document to a file.
' "textOutlineEffect.docx" is the name of the output file where the document will be saved.
doc.SaveAs("textOutlineEffect.docx")

Text Outline Effect Properties
The text outline effect offers a variety of customizable properties to suit any design need. Below are the properties along with their descriptions:
- PenAlignment: Gets or sets the alignment of the pen used for the outline effect.
- LineCapType: Gets or sets the type of line cap used for the outline effect.
- LineWidth: Gets or sets the width of the outline effect line. Note: The width is specified in points (1/72 inch).
- CompoundLineType: Gets or sets the type of compound line used for the outline effect.
- LineJoin: Gets or sets the stroke join style used for the outline effect.
- Color: Gets or sets the solid fill color for the outline effect.
- PresetLineDash: Gets or sets the preset line dash style for the outline effect.
:path=/static-assets/word/content-code-examples/how-to/text-effect-customized-text-outline-effect.cs
using IronWord;
using IronWord.Models;
using IronWord.Models.Enums;
// Create a new Word document
WordDocument doc = new WordDocument();
// Create and configure text style
TextStyle textStyle = new TextStyle()
{
TextEffect = new TextEffect()
{
TextOutlineEffect = new TextOutlineEffect()
{
Color = IronWord.Models.Color.Red, // Set text outline color to red
CompoundLineType = CompoundLineValues.Double, // Use a double line for the outline
LineCapType = LineCapValues.Round, // Set rounded ends for the lines
LineJoin = StrokeJoinStyleValues.Bevel, // Set the join style to bevel
LineWidth = 0.3, // Set the width of the outline line
PenAlignment = PenAlignmentValues.Center, // Align the pen to the center
PresetLineDash = PresetLineDashValues.Solid // Ensure the line is solid
}
}
};
// Add text with the configured style
TextElement textElement = doc.AddText("Customized text outline");
textElement.Style = textStyle;
// Export the new Word document with the customized text
doc.SaveAs("customizedTextOutlineEffect.docx");
// The code above initializes a new Word document and applies a specific text style to a text string.
// The TextStyle object is configured to use a red double-outline effect with rounded line caps,
// a bevel line join, a centered pen alignment, and solid lines.
Imports IronWord
Imports IronWord.Models
Imports IronWord.Models.Enums
' Create a new Word document
Private doc As New WordDocument()
' Create and configure text style
Private textStyle As New TextStyle() With {
.TextEffect = New TextEffect() With {
.TextOutlineEffect = New TextOutlineEffect() With {
.Color = IronWord.Models.Color.Red,
.CompoundLineType = CompoundLineValues.Double,
.LineCapType = LineCapValues.Round,
.LineJoin = StrokeJoinStyleValues.Bevel,
.LineWidth = 0.3,
.PenAlignment = PenAlignmentValues.Center,
.PresetLineDash = PresetLineDashValues.Solid
}
}
}
' Add text with the configured style
Private textElement As TextElement = doc.AddText("Customized text outline")
textElement.Style = textStyle
' Export the new Word document with the customized text
doc.SaveAs("customizedTextOutlineEffect.docx")
' The code above initializes a new Word document and applies a specific text style to a text string.
' The TextStyle object is configured to use a red double-outline effect with rounded line caps,
' a bevel line join, a centered pen alignment, and solid lines.

Frequently Asked Questions
What is a text outline effect?
A text outline effect adds a visible border around the characters of text, enhancing readability or visual impact. It can be customized in terms of color, thickness, and style.
How can I start using IronWord to add a text outline effect?
To get started with IronWord, download a C# library designed for text editing, such as IronWord, which facilitates adding text effects.
What steps are involved in adding a text outline effect using IronWord?
The steps include downloading a C# library, applying the text effect, configuring the TextOutlineEffect properties, and exporting the edited Word document.
How do I apply a preset text outline effect in IronWord?
You can apply a preset text outline effect using the static named instance of the TextOutlineEffect class.
What properties can be customized in the text outline effect?
The properties include PenAlignment, LineCapType, LineWidth, CompoundLineType, LineJoin, Color, and PresetLineDash.
Can I customize the text outline effect in IronWord?
Yes, you can customize the text outline effect by configuring properties like line width, color, and style using the TextOutlineEffect object.
How do I define a text style with a text outline effect in C#?
Define a TextStyle object and populate the TextOutlineEffect property with a TextOutlineEffect object, then assign it to the TextEffect property of your text.
What is the unit of measurement for the line width in a text outline effect?
The line width is specified in points, where one point is 1/72 of an inch.
Can I export the document after applying a text outline effect?
Yes, after applying a text outline effect, you can export the edited Word document as a new file.
What is the purpose of using a text outline effect?
The purpose of using a text outline effect is to make text stand out against backgrounds or to create a stylized appearance, enhancing readability or visual impact.