Comment configurer les paramètres d'impression dans PDF en utilisant 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

Questions Fréquemment Posées

Comment puis-je ajouter un effet de dégradé au texte dans un document Word en utilisant C#?

Vous pouvez ajouter un effet de dégradé au texte dans un document Word en utilisant la bibliothèque C# d'IronWord. Tout d'abord, téléchargez la bibliothèque, puis appliquez l'effet de texte à un texte nouveau ou existant. Utilisez un effet de dégradé prédéfini via l'instance nommée statique de la classe Gradient et personnalisez-le en configurant les propriétés de GradientEffect.

Quelles sont les étapes pour appliquer un effet de dégradé en utilisant IronWord ?

Pour appliquer un effet de dégradé en utilisant IronWord, suivez ces étapes : téléchargez la bibliothèque C#, appliquez le dégradé au texte, utilisez un effet de dégradé prédéfini de la classe Gradient, configurez les propriétés de GradientEffect, et enfin, exportez le document modifié.

Comment créer un objet TextStyle avec un effet de dégradé dans IronWord ?

Dans IronWord, créez un objet TextStyle et remplissez la propriété GradientEffect avec un objet Gradient. Assignez cet TextStyle à la propriété TextEffect pour l'appliquer à votre texte.

Quel est le but des arrêts de dégradé dans IronWord ?

Les arrêts de dégradé dans IronWord sont des points au sein d'un dégradé où une couleur spécifique est définie. Ils sont contrôlés à l'aide de la classe GradientStop, qui inclut des propriétés telles que Color pour la couleur du schéma et StopPoint pour la position de l'arrêt du dégradé.

Les arrêts de dégradé peuvent-ils être personnalisés dans IronWord ?

Oui, vous pouvez personnaliser les arrêts de dégradé dans IronWord en ajoutant des objets GradientStop avec des couleurs et positions spécifiques à la liste StopPoints d'un objet Gradient, permettant des effets de dégradé personnalisés.

Quelles sont les propriétés clés de la classe Gradient dans IronWord ?

La classe Gradient dans IronWord comprend des propriétés clés telles que StopPoints, qui définissent les arrêts de dégradé, LinearShadeScaled, qui indique si l'ombrage linéaire est mis à l'échelle, et LinearShadeAngle, qui définit l'angle de l'ombrage linéaire.

Comment exportez-vous un document Word après avoir ajouté un effet de dégradé en utilisant IronWord ?

Après avoir ajouté un effet de dégradé au texte en utilisant IronWord, vous pouvez exporter le document Word modifié en l'enregistrant en tant que nouveau fichier dans le format désiré avec les effets de dégradé appliqués.

Curtis Chau
Rédacteur technique

Curtis Chau détient un baccalauréat en informatique (Université de Carleton) et se spécialise dans le développement front-end avec expertise en Node.js, TypeScript, JavaScript et React. Passionné par la création d'interfaces utilisateur intuitives et esthétiquement plaisantes, Curtis aime travailler avec des frameworks modernes ...

Lire la suite
Prêt à commencer?
Nuget Téléchargements 25,807 | Version : 2025.11 vient de sortir