DocumentTheme Property

Gets the Theme object for this document.

Namespace:  Aspose.Words
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.9.0


public Theme Theme { get; }

Property Value

Type: Theme


Shows how to set custom theme colors and fonts.
Document doc = new Document(MyDir + "Theme colors.docx");

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

// These fonts will be inherited by some styles like "Heading 1" and "Subtitle"
theme.MajorFonts.Latin = "Courier New";
theme.MinorFonts.Latin = "Agency FB";

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);

// This collection of colors corresponds to the color palette from Microsoft Word which appears when changing shading or font color 
ThemeColors colors = theme.Colors;

// We will set the color of each color palette column going from left to right like this
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;

// We can also set colors for hyperlinks like this
colors.Hyperlink = Color.Black;
colors.FollowedHyperlink = Color.Gray;

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

See Also