How to Add Text Outline Effect to Text in C# | IronWord

How to Add a Text Outline Effect in C#

Adding a text outline effect in C# creates a visible border around characters, enhancing readability and visual impact. Use IronWord's TextOutlineEffect class to apply customizable outlines with control over color, thickness, and style. This technique is particularly valuable for creating eye-catching headers, watermarks, or emphasizing important content in business documents and reports.

Text outlines serve multiple purposes in document design: they improve contrast against complex backgrounds, create visual hierarchy, and add professional polish to presentations and reports. Whether you're generating invoices, creating marketing materials, or producing technical documentation, text outlines can make your content more engaging and easier to read.

Quickstart: Apply a Default Text Outline Effect Instantly

With just one line, create a TextStyle that applies a ready-made text outline via TextOutlineEffect.DefaultEffect. It provides text enhancement without complex setup. This approach is perfect for rapid prototyping or when you need a quick visual enhancement without fine-tuning specific parameters.

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.

    using IronWord;
    using IronWord.Models;
    
    WordDocument doc = new WordDocument();
    TextStyle textStyle = new TextStyle();
    textStyle.TextEffect = new TextEffect() { TextOutlineEffect = TextOutlineEffect.DefaultEffect };
    Paragraph paragraph = new Paragraph();
    Run textRun = new Run(new TextContent("Outlined Text"));
    textRun.Style = textStyle;
    paragraph.AddChild(textRun);
    doc.AddParagraph(paragraph);
    doc.SaveAs("outline.docx");
  3. Deploy to test on your live environment

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

How Do I Add a Text Outline Effect to Word Documents?

Why Should I Use TextOutlineEffect for Text Styling?

To apply a text outline effect, create a TextStyle and populate its TextEffect property with a TextOutlineEffect. Then create a Paragraph, followed by a Run containing TextContent. Assign the TextStyle to the Run (not the TextContent), then use AddChild to add the Run to the Paragraph. This follows the document hierarchy: Document → Paragraph → Run → TextContent.

The TextOutlineEffect class provides a comprehensive API for controlling every aspect of your text outlines. Unlike basic text formatting options, it offers granular control over outline properties such as line width, color, pen alignment, and dash patterns. This level of control is essential when creating professional documents that need to meet specific branding guidelines or accessibility requirements.

For business applications, text outlines can significantly improve document readability when printing on various paper stocks or when documents will be viewed on different devices. The outline creates a buffer zone around each character, ensuring text remains legible even against busy backgrounds or low-contrast scenarios.

What's the Basic Code Pattern for Adding Outlines?

:path=/static-assets/word/content-code-examples/how-to/text-effect-text-outline-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()
{
    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")
$vbLabelText   $csharpLabel
Microsoft Word showing 'Hello World' text with golden outline effect applied via Home tab font options

This basic pattern demonstrates the fundamental approach to applying text outlines. The code creates a new document, defines a text style with the default outline effect, applies it to text, and saves the result. The DefaultEffect provides a balanced outline that works well for most scenarios, featuring a subtle width and complementary color that enhances rather than overwhelms the text.

How Can I Customize Text Outline Effect Properties?

What Properties Control the Outline Appearance?

The text outline effect offers a variety of customizable properties to suit any design need. Understanding these properties enables you to create outlines that perfectly match your document's visual requirements and brand guidelines. Below are the properties along with their descriptions:

Property Description
PenAlignment Gets or sets the alignment of the pen. Controls whether the outline appears inside, outside, or centered on text
LineCapType Gets or sets the type of line cap used for the outline effect. Options include flat, round, or square caps that affect how line ends appear
LineWidth Gets or sets the width of the outline effect line. Width is specified in points (1/72 inch). Typical values range from 0.1 to 2.0
CompoundLineType Gets or sets the type of compound line used for the outline effect. Enables creation of double, triple, or other multi-line outline styles
LineJoin Gets or sets the stroke join style used for the outline effect. Determines how outline corners connect (miter, round, or bevel)
Color Gets or sets the solid fill color for the outline effect. Accepts any valid color value for maximum flexibility
PresetLineDash Gets or sets the preset line dash style for the outline effect. Choose from solid, dashed, dotted, or custom patterns

Each property serves a specific purpose in creating professional-looking text outlines. For instance, LineWidth directly impacts visual prominence – thinner outlines (0.1-0.3 points) create subtle emphasis, while thicker outlines (1.0-2.0 points) make bold statements. The Color property is crucial for maintaining brand consistency and ensuring adequate contrast for accessibility.

How Do I Apply Custom Outline Properties?

: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 new Word document
WordDocument doc = new WordDocument();

// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
    TextOutlineEffect = new TextOutlineEffect()
    {
        Color = IronWord.Models.Color.Red,
        CompoundLineType = CompoundLineValues.Double,
        LineCapType = LineCapValues.Round,
        LineJoin = StrokeJoinStyleValues.Bevel,
        LineWidth = 0.3,
        PenAlignment = PenAlignmentValues.Center,
        presetLineDash = PresetLineDashValues.Solid
    },
};

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

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

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

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

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

' 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 = 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
    }
}

' Create paragraph
Dim paragraph As New Paragraph()

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

' Add run to paragraph
paragraph.AddChild(textRun)

' Add paragraph to document
doc.AddParagraph(paragraph)

' Export new Word document
doc.SaveAs("customizedTextOutlineEffect.docx")
$vbLabelText   $csharpLabel
Microsoft Word showing red text with black outline effect and formatting ribbon with text outline controls

This advanced example showcases the full power of custom outline configuration. The code creates a distinctive red outline with a double line style, demonstrating how multiple properties work together to achieve specific visual effects. The round line caps and bevel joins create smooth, professional-looking outlines that work well for headers and titles.

When implementing custom outlines in production applications, consider creating reusable style templates. Define standard outline configurations for different document elements (headers, subheaders, emphasis text) and store them as constants or configuration settings. This approach ensures consistency across your document generation pipeline and simplifies maintenance when brand guidelines change.

For optimal results, test your outline effects across different output formats and viewing conditions. What looks good on screen might need adjustment for print output. Consider factors like printer resolution, paper color, and viewing distance when selecting outline widths and colors. The flexibility of IronWord's TextOutlineEffect class allows you to fine-tune these parameters programmatically based on output requirements.

Frequently Asked Questions

How do I add a text outline effect to Word documents in C#?

To add text outline effects in C#, use IronWord's TextOutlineEffect class. Create a TextStyle object and populate its TextOutlineEffect property with a TextOutlineEffect object. For a quick implementation, use TextOutlineEffect.DefaultEffect which applies a ready-made outline with just one line of code.

What are the main benefits of using text outline effects in documents?

Text outline effects created with IronWord enhance readability by improving contrast against complex backgrounds, creating visual hierarchy, and adding professional polish to documents. They're particularly valuable for headers, watermarks, invoices, marketing materials, and technical documentation where content needs to stand out.

Can I customize the appearance of text outlines beyond the default settings?

Yes, IronWord's TextOutlineEffect class provides comprehensive customization options including control over line width, color, pen alignment, and dash patterns. This granular control allows you to meet specific branding guidelines or accessibility requirements for professional documents.

What's the quickest way to apply a text outline effect?

The fastest method is using the single-line approach with IronWord: new TextStyle { TextEffect = new TextEffect { TextOutlineEffect = TextOutlineEffect.DefaultEffect } }. This instantly applies a preset outline effect without complex setup, perfect for rapid prototyping.

How does applying text outlines improve document printing and viewing?

Text outlines created with IronWord significantly improve readability when printing on various paper stocks or viewing on different devices. The outline creates a buffer zone around each character, ensuring text remains legible even against busy backgrounds or in low-contrast scenarios.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 32,664 | Version: 2026.2 just released