Cómo Configurar la Impresión en PDF Usando C# | IronPrint

How to Add Gradient Effect to Text

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

A gradient effect on text involves applying a smooth transition of colors across the characters or background of text, creating a blend from one color to another or multiple colors. This effect adds depth, visual interest, and a dynamic appearance to the text, making it stand out and enhancing its aesthetic appearance. Gradient effects can be linear (colors transition in a straight line) or radial (colors transition from a central point outward).

Quickstart: Add a Gradient Effect to Text with IronWord

Here’s a simple example showing how to use IronWord to apply a built-in gradient effect to text in just a few lines—perfect if you want to get started quickly and see visual results instantly.

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.

    var doc = new IronWord.WordDocument();
    doc.AddText("Test").Style = new IronWord.Models.TextStyle(){ TextEffect = new IronWord.Models.TextEffect(){ GradientEffect = IronWord.Models.Gradient.DefaultGray } };
    doc.SaveAs("out.docx");
  3. Deploy to test on your live environment

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

Add Gradient Effect

To specify the gradient effect for the text, create the TextStyle object and populate the GradientEffect property with a Gradient 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-gradient-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()
{
    GradientEffect = Gradient.DefaultGray,
};

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

// Export new Word document
doc.SaveAs("gradientEffect.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 {.GradientEffect = Gradient.DefaultGray}

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

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

Gradient Effect Properties

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

GradientStop

  • Color: Gets or sets the scheme color of the gradient stop.
  • StopPoint: Gets or sets the position of the gradient stop.

Gradient stops are points within a gradient where a specific color is defined.

Gradient

  • StopPoints: Gets or sets the list of gradient stops defining the gradient fill.
  • LinearShadeScaled: Gets or sets a value indicating whether the linear shade is scaled.
  • LinearShadeAngle: Gets or sets the angle of the linear shade.
:path=/static-assets/word/content-code-examples/how-to/text-effect-customized-gradient-effect.cs
using IronWord;
using IronWord.Models;
using System.Collections.Generic;

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

// Create gradient stops
GradientStop firstGradientStop = new GradientStop()
{
    Color = IronWord.Models.Color.Aqua,
    StopPoint = 1
};
GradientStop secondGradientStop = new GradientStop()
{
    Color = IronWord.Models.Color.OrangeRed,
    StopPoint = 10
};

// Create and configure text style
TextStyle textStyle = new TextStyle();
textStyle.TextEffect = new TextEffect()
{
    GradientEffect = new Gradient()
    {
        StopPoints = new List<GradientStop> { firstGradientStop, secondGradientStop },
        LinearShadeAngle = 45,
        LinearShadeScaled = true,
    }
};

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

// Export new Word document
doc.SaveAs("customizedGradientEffect.docx");
Imports IronWord
Imports IronWord.Models
Imports System.Collections.Generic

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

' Create gradient stops
Private firstGradientStop As New GradientStop() With {
	.Color = IronWord.Models.Color.Aqua,
	.StopPoint = 1
}
Private secondGradientStop As New GradientStop() With {
	.Color = IronWord.Models.Color.OrangeRed,
	.StopPoint = 10
}

' Create and configure text style
Private textStyle As New TextStyle()
textStyle.TextEffect = New TextEffect() With {
	.GradientEffect = New Gradient() With {
		.StopPoints = New List(Of GradientStop) From {firstGradientStop, secondGradientStop},
		.LinearShadeAngle = 45, .LinearShadeScaled = True
	}
}

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

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

Preguntas Frecuentes

¿Cómo puedo añadir un efecto degradado al texto en un documento de Word usando C#?

Puedes añadir un efecto degradado al texto en un documento de Word utilizando la biblioteca C# de IronWord. Primero, descarga la biblioteca, luego aplica el efecto de texto a texto nuevo o existente. Usa un efecto degradado predefinido a través de la instancia estática nombrada de la clase Gradient y personalízalo configurando las propiedades de GradientEffect.

¿Cuáles son los pasos para aplicar un efecto degradado usando IronWord?

Para aplicar un efecto degradado usando IronWord, sigue estos pasos: descarga la biblioteca C#, aplica el degradado al texto, utiliza un efecto degradado predefinido de la clase Gradient, configura las propiedades de GradientEffect y finalmente, exporta el documento editado.

¿Cómo crear un objeto TextStyle con un efecto degradado en IronWord?

En IronWord, crea un objeto TextStyle y rellena la propiedad GradientEffect con un objeto Gradient. Asigna este TextStyle a la propiedad TextEffect para aplicarlo a tu texto.

¿Cuál es el propósito de los puntos de parada de gradiente en IronWord?

Los puntos de parada de gradiente en IronWord son puntos dentro de un degradado donde se define un color específico. Se controlan utilizando la clase GradientStop, que incluye propiedades como Color para el color del esquema y StopPoint para la posición del punto de parada del gradiente.

¿Se pueden personalizar los puntos de gradiente en IronWord?

Sí, puedes personalizar los puntos de parada de gradiente en IronWord añadiendo objetos GradientStop con colores y posiciones específicos a la lista StopPoints de un objeto Gradient, permitiendo efectos de degradado personalizados.

¿Cuáles son las propiedades clave de la clase Gradient en IronWord?

La clase Gradient en IronWord incluye propiedades clave como StopPoints, que definen los puntos de parada de gradiente, LinearShadeScaled, que indica si la sombra lineal está escalada, y LinearShadeAngle, que establece el ángulo de la sombra lineal.

¿Cómo exportar un documento de Word después de añadir un efecto degradado usando IronWord?

Después de añadir un efecto degradado al texto usando IronWord, puedes exportar el documento de Word editado guardándolo como un nuevo archivo en tu formato deseado con los efectos degradados aplicados.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 25,807 | Versión: 2025.11 recién lanzado