Customize Changes Styles

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Comparison MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-comparison -- dnx GroupDocs.Comparison.Mcp --yes
Folders, licensing and more →

GroupDocs.Comparison for Python via .NET lets you customize how inserted, deleted, and changed items are rendered in the result document — highlight colour, font colour, bold, italic, underline, and strikethrough.

To customize change styles:

  1. Instantiate a Comparer with a source path or stream.
  2. Call add() with the target.
  3. Create a CompareOptions instance and configure inserted_item_style, deleted_item_style, and changed_item_style with StyleSettings.
  4. Call compare() with the options and a result path or stream.

Example 1: Custom change styles (file paths)

from groupdocs.comparison import Comparer
from groupdocs.comparison import Color
from groupdocs.comparison.options import CompareOptions, StyleSettings


def customize_changes_styles():
    options = CompareOptions()

    inserted = StyleSettings()
    inserted.font_color = Color.from_name("green")
    inserted.highlight_color = Color.from_name("red")
    inserted.is_underline = True
    inserted.is_bold = True
    options.inserted_item_style = inserted

    deleted = StyleSettings()
    deleted.font_color = Color.from_name("brown")
    deleted.highlight_color = Color.from_name("azure")
    deleted.is_strikethrough = True
    options.deleted_item_style = deleted

    changed = StyleSettings()
    changed.font_color = Color.from_name("firebrick")
    changed.highlight_color = Color.from_name("crimson")
    changed.is_italic = True
    options.changed_item_style = changed

    with Comparer("./source.docx") as comparer:
        comparer.add("./target.docx")
        comparer.compare("./result.docx", options)

if __name__ == "__main__":
    customize_changes_styles()

source.docx is the source file used in this example. Click here to download it.

target.docx is the target file used in this example. Click here to download it.

Binary file (DOCX, 25 KB)

Download full output

Use case: enforce corporate branding for change highlights in contract reviews.

Example 2: Custom change styles (streams)

The same styling, but operating entirely through streams:

from groupdocs.comparison import Comparer
from groupdocs.comparison import Color
from groupdocs.comparison.options import CompareOptions, StyleSettings


def customize_changes_styles_stream():
    options = CompareOptions()
    options.inserted_item_style = StyleSettings()
    options.inserted_item_style.font_color = Color.from_name("green")
    options.inserted_item_style.is_underline = True

    options.deleted_item_style = StyleSettings()
    options.deleted_item_style.is_strikethrough = True

    options.changed_item_style = StyleSettings()
    options.changed_item_style.is_italic = True

    with open("./source.docx", "rb") as source_stream, \
         open("./target.docx", "rb") as target_stream, \
         open("./result.docx", "wb") as out_stream:
        with Comparer(source_stream) as comparer:
            comparer.add(target_stream)
            comparer.compare(out_stream, options)

if __name__ == "__main__":
    customize_changes_styles_stream()

source.docx is the source file used in this example. Click here to download it.

target.docx is the target file used in this example. Click here to download it.

Binary file (DOCX, 25 KB)

Download full output

Use case: process documents fully in memory (no temp files) while keeping brand-compliant styling.