Customize changes styles
Leave feedback
On this page
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:
- Instantiate the
Comparer
object with a source path or stream. - Call
add()
and provide the target path or stream. - Instantiate
CompareOptions
and configureInsertedItemStyle
,DeletedItemStyle
, andChangedItemStyle
. - Call
compare()
with the options and a result path or stream.
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.
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.
Was this page helpful?
Any additional feedback you'd like to share with us?
Please tell us how we can improve this page.
Thank you for your feedback!
We value your opinion. Your feedback will help us improve our documentation.