Working with Document Themes
Working with Document Themes
This guide shows how to read and customize the color and font scheme that Word documents share
with other Office applications – the document theme – using Theme, ThemeColors, and
ThemeFonts in Aspose.Words FOSS for .NET. A document’s theme is the palette and font
pairing that theme-aware formatting elsewhere in the object model refers to instead of
hardcoding a specific color or font name.
The Theme Object
Document.Theme returns a Theme instance for the document. Theme.Colors is a
ThemeColors object holding the document’s twelve theme colors; Theme.MajorFonts and
Theme.MinorFonts are ThemeFonts objects holding the heading and body font sets respectively.
Theme Colors
ThemeColors exposes twelve writable Color properties: Dark1, Light1, Dark2, Light2,
Accent1 through Accent6, Hyperlink, and FollowedHyperlink. Formatting objects elsewhere
in the document – Border.ThemeColor, Shading.ForegroundPatternThemeColor /
BackgroundPatternThemeColor, Fill.ForeThemeColor / BackThemeColor,
Stroke.ForeThemeColor / BackThemeColor, and Font.ThemeColor – hold a ThemeColor enum
value (Dark1, Light1, Dark2, Light2, Accent1-Accent6, Hyperlink,
FollowedHyperlink, plus Text1, Text2, Background1, Background2, and None) that
identifies which theme color slot applies; the actual Color value for that slot comes from
the corresponding ThemeColors property on Document.Theme.Colors.
Theme Fonts
ThemeFonts exposes three writable string properties: Latin (for Latin-script characters),
EastAsian, and ComplexScript – the font names used for each script when a formatting object
defers to the theme. Font.ThemeFont, ThemeFontAscii, ThemeFontFarEast, ThemeFontOther,
and ThemeFontBi each hold a ThemeFont enum value (Major, Minor, or None) identifying
whether a given Font object defers to Theme.MajorFonts or Theme.MinorFonts for a
particular script range, rather than storing an explicit font name of its own.
Tips and Best Practices
- Change a color across every theme-aware border, shading, fill, and font in one edit by
updating the relevant
ThemeColorsproperty onDocument.Theme.Colors, instead of walking the document to update each formatting object individually. - Check whether a formatting object’s
ThemeColororThemeFontproperty isNonebefore assuming it defers to the theme –Nonemeans it carries its own explicitColoror font name instead. Theme.MajorFontstypically supplies heading fonts andTheme.MinorFontsbody fonts, matching Word’s own theme font picker.
Common Issues
| Issue | Cause | Fix |
|---|---|---|
Changing Document.Theme.Colors.Accent1 doesn’t affect a shape’s fill | The shape’s Fill.ForeThemeColor is ThemeColor.None, so it uses an explicit color instead of a theme slot | Set Fill.ForeThemeColor to the desired ThemeColor value so it defers to the theme |
A Font’s rendered font doesn’t match Theme.MajorFonts.Latin | The Font.ThemeFont (or script-specific variant) is ThemeFont.None, so the font’s own name is used instead | Set the relevant ThemeFont property to Major or Minor |
FAQ
How do I read a document’s theme colors?
Read Document.Theme.Colors, a ThemeColors object with Color properties for each of the
twelve theme color slots – Dark1, Light1, Dark2, Light2, Accent1-Accent6,
Hyperlink, and FollowedHyperlink.
How do I change the document’s accent color everywhere it’s used?
Set Document.Theme.Colors.Accent1 (or whichever accent slot) to a new Color; every
formatting object whose ThemeColor property references that slot picks up the change.
What’s the difference between ThemeColors and ThemeColor?
ThemeColors (on Document.Theme.Colors) is the object holding the twelve actual Color
values for the document. ThemeColor is the enum used elsewhere (Border, Shading, Fill,
Stroke, Font) to reference one of those slots by name instead of storing a color directly.
How do I set which theme font a Font object uses?
Set Font.ThemeFont (or the script-specific ThemeFontAscii / ThemeFontFarEast /
ThemeFontOther / ThemeFontBi) to ThemeFont.Major or ThemeFont.Minor; the actual font
name then comes from Document.Theme.MajorFonts or MinorFonts.
API Reference Summary
| Class / Enum | Description |
|---|---|
Theme | Document theme, via Document.Theme; MajorFonts, MinorFonts, Colors |
ThemeColors | Twelve theme Color slots: Dark1, Light1, Dark2, Light2, Accent1-Accent6, Hyperlink, FollowedHyperlink |
ThemeFonts | Theme font names per script: Latin, EastAsian, ComplexScript |
ThemeColor | Enum identifying a theme color slot; used by Border, Shading, Fill, Stroke, Font |
ThemeFont | Enum identifying Major/Minor theme font usage; used by Font |