Customize changes styles

GroupDocs.Comparison for Python via .NET provides a rich set of options to control the look of detected changes in the result document.

To compare two documents with custom change style settings, follow these steps:

  1. Instantiate the Comparer object with a source path or stream.
  2. Call add() and provide the target path or stream.
  3. Instantiate CompareOptions and configure InsertedItemStyle, DeletedItemStyle, and ChangedItemStyle.
  4. Call compare() with the options and a result path or stream.

Compare documents from local disk with custom change styles

Configure custom highlight, font, and style settings for inserted, deleted, and changed items, then run the comparison to produce a styled result.

import groupdocs.comparison as gc

source_path = "source.docx"
target_path = "target.docx"
result_path = "result.docx"

options = gc.CompareOptions()
options.inserted_item_style = gc.StyleSettings(
    highlight_color=gc.Color.from_name("red"),
    font_color=gc.Color.from_name("green"),
    is_underline=True,
    is_bold=True,
    is_strikethrough=True,
    is_italic=True,
)
options.deleted_item_style = gc.StyleSettings(
    highlight_color=gc.Color.from_name("azure"),
    font_color=gc.Color.from_name("brown"),
    is_underline=True,
    is_bold=True,
    is_strikethrough=True,
    is_italic=True,
)
options.changed_item_style = gc.StyleSettings(
    highlight_color=gc.Color.from_name("crimson"),
    font_color=gc.Color.from_name("firebrick"),
    is_underline=True,
    is_bold=True,
    is_strikethrough=True,
    is_italic=True,
)

with gc.Comparer(source_path) as comparer:
    comparer.add(target_path)
    comparer.compare(result_path, options)

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

Compare documents from stream with custom change styles

Load documents as streams, apply custom StyleSettings for all change types, and write the styled result to a stream.

import groupdocs.comparison as gc

options = gc.CompareOptions()
options.inserted_item_style = gc.StyleSettings(
    highlight_color=gc.Color.from_name("red"),
    font_color=gc.Color.from_name("green"),
    is_underline=True,
    is_bold=True,
    is_strikethrough=True,
    is_italic=True,
)
options.deleted_item_style = gc.StyleSettings(
    highlight_color=gc.Color.from_name("azure"),
    font_color=gc.Color.from_name("brown"),
    is_underline=True,
    is_bold=True,
    is_strikethrough=True,
    is_italic=True,
)
options.changed_item_style = gc.StyleSettings(
    highlight_color=gc.Color.from_name("crimson"),
    font_color=gc.Color.from_name("firebrick"),
    is_underline=True,
    is_bold=True,
    is_strikethrough=True,
    is_italic=True,
)

with open("source.docx", "rb") as src, open("target.docx", "rb") as tgt, open("result.docx", "wb") as out_stream:
    with gc.Comparer(src) as comparer:
        comparer.add(tgt)
        comparer.compare(out_stream, options)

The result document will highlight inserted, deleted, and changed items using your specified styles.

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

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.