Search Results for

    Show / Hide Table of Contents

    Class ColorHelper

    A static helper class for color manipulation.

    Inheritance
    System.Object
    ColorHelper
    Namespace: IronWord.Models.Extensions
    Assembly: IronWord.dll
    Syntax
    public static class ColorHelper : Object

    A hexadecimal string for any IronWord Color comes from ColorHelper. The single method, ToHex, is an extension on Color, so any color value in a document, a font color, a shading fill, a border, converts to its hex code with one call. The returned string includes the alpha channel, and the conversion accounts for the color's opacity by adjusting the RGB values, which is what produces a correct code for a semi-transparent color rather than a flat opaque one.

    Because ToHex is declared as an extension method, it reads as a method on the color itself once the IronWord.Models.Extensions namespace is in scope. Use it whenever a color needs to leave the object model as text, when logging the color applied to a run, exporting a style to CSS or another format, or comparing two fills by their string value. The input is the same Color you set elsewhere in the API, so no separate conversion type is involved. The styled text how-to covers applying color and other formatting to text.

    string hex = new Color("#FF0000").ToHex();

    The gradient text effect how-to works with color stops in a document.

    Methods

    ToHex(Color)

    Converts a Color object to its hexadecimal representation.

    Declaration
    public static string ToHex(this Color c)
    Parameters
    Type Name Description
    Color c

    The Color object to convert.

    Returns
    Type Description
    System.String

    The hexadecimal representation of the color, including alpha channel.

    Remarks

    This method considers the opacity of the color and adjusts the RGB values accordingly. This is essential for ensuring the correct hex code is generated for semi-transparent colors.

    ☀
    ☾
    Downloads
    • Download with NuGet
    • Start for Free
    In This Article
    Back to top
    Install with NuGet