Customize Changes Styles
Leave feedback
On this page
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:
- Instantiate a
Comparerwith a source path or stream. - Call
add()with the target. - Create a
CompareOptionsinstance and configureinserted_item_style,deleted_item_style, andchanged_item_stylewithStyleSettings. - Call
compare()with the options and a result path or stream.
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)
Use case: enforce corporate branding for change highlights in contract reviews.
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)
Use case: process documents fully 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.