Get Source and Target Text from Files
Leave feedback
On this page
GroupDocs.Comparison for Python via .NET records the source and target text for each detected change. Read source_text and target_text on each ChangeInfo to surface the before/after pair.
from groupdocs.comparison import Comparer
def get_source_and_target_text():
with Comparer("./source.docx") as comparer:
comparer.add("./target.docx")
comparer.compare("./result.docx")
for change in comparer.get_changes():
print(f"Source text: {change.source_text}")
print(f"Target text: {change.target_text}\n")
if __name__ == "__main__":
get_source_and_target_text()
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: extract changed text pairs to power side-by-side diff review tools.
from groupdocs.comparison import Comparer
def get_source_and_target_text_stream():
with open("./source.docx", "rb") as source_stream, \
open("./target.docx", "rb") as target_stream:
with Comparer(source_stream) as comparer:
comparer.add(target_stream)
comparer.compare("./result.docx")
for change in comparer.get_changes():
print(f"Source text: {change.source_text}")
print(f"Target text: {change.target_text}\n")
if __name__ == "__main__":
get_source_and_target_text_stream()
source.docx is the source file used in this example. Click here to download it.
Binary file (DOCX, 25 KB)
Use case: feed structured change text into analytics or translation workflows.
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.