Theme

Theme class

Represents document Theme, and provides access to main theme parts including MajorFonts, MinorFonts and Colors

To learn more, visit the Working with Styles and Themes documentation article.

public class Theme

Constructors

NameDescription
Theme()The default constructor.

Properties

NameDescription
Colors { get; }Allows to specify the set of theme colors for the document.
MajorFonts { get; }Allows to specify the set of major fonts for different languages.
MinorFonts { get; }Allows to specify the set of minor fonts for different languages.

Examples

Shows how to set custom colors and fonts for themes.

Document doc = new Document(MyDir + "Theme colors.docx");

// The "Theme" object gives us access to the document theme, a source of default fonts and colors.
Theme theme = doc.Theme;

// Some styles, such as "Heading 1" and "Subtitle", will inherit these fonts.
theme.MajorFonts.Latin = "Courier New";
theme.MinorFonts.Latin = "Agency FB";

// Other languages may also have their custom fonts in this theme.
Assert.AreEqual(string.Empty, theme.MajorFonts.ComplexScript);
Assert.AreEqual(string.Empty, theme.MajorFonts.EastAsian);
Assert.AreEqual(string.Empty, theme.MinorFonts.ComplexScript);
Assert.AreEqual(string.Empty, theme.MinorFonts.EastAsian);

// The "Colors" property contains the color palette from Microsoft Word,
// which appears when changing shading or font color.
// Apply custom colors to the color palette so we have easy access to them in Microsoft Word
// when we, for example, change the font color via "Home" -> "Font" -> "Font Color",
// or insert a shape, and then set a color for it via "Shape Format" -> "Shape Styles".
ThemeColors colors = theme.Colors;
colors.Dark1 = Color.MidnightBlue;
colors.Light1 = Color.PaleGreen;
colors.Dark2 = Color.Indigo;
colors.Light2 = Color.Khaki;

colors.Accent1 = Color.OrangeRed;
colors.Accent2 = Color.LightSalmon;
colors.Accent3 = Color.Yellow;
colors.Accent4 = Color.Gold;
colors.Accent5 = Color.BlueViolet;
colors.Accent6 = Color.DarkViolet;

// Apply custom colors to hyperlinks in their clicked and un-clicked states.
colors.Hyperlink = Color.Black;
colors.FollowedHyperlink = Color.Gray;

doc.Save(ArtifactsDir + "Themes.CustomColorsAndFonts.docx");

See Also