Created
March 7, 2024 16:37
-
-
Save aspose-com-gists/d3410b7160a7b6480c2959c75cebd17e to your computer and use it in GitHub Desktop.
Compare Word, PDF, and PPT Documents in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code example demonstrates how to compare two Word files in Python | |
import aspose.words as aw | |
from datetime import date | |
# load first document | |
doc = aw.Document("Document.docx") | |
# load second document | |
doc2 = aw.Document("Document2.docx") | |
# compare documents | |
doc.compare(doc2, "user", date.today()) | |
# save the document to get the revisions | |
if (doc.revisions.count > 0): | |
doc.save("Compared_Document.docx") | |
else: | |
print("Documents are equal") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code example demonstrates how to compare two PDF files in Python | |
import aspose.words as aw | |
from datetime import date | |
# Load PDF files | |
PDF1 = aw.Document("Document.pdf") | |
PDF2 = aw.Document("Document2.pdf") | |
# Convert PDF files to Word format | |
PDF1.save("first.docx", aw.SaveFormat.DOCX) | |
PDF2.save("second.docx", aw.SaveFormat.DOCX) | |
# Load converted Word documents | |
DOC1 = aw.Document("first.docx") | |
DOC2 = aw.Document("second.docx") | |
# Set comparison options | |
options = aw.comparing.CompareOptions() | |
options.ignore_formatting = True | |
options.ignore_headers_and_footers = True | |
options.ignore_case_changes = True | |
options.ignore_tables = True | |
options.ignore_fields = True | |
options.ignore_comments = True | |
options.ignore_textboxes = True | |
options.ignore_footnotes = True | |
# DOC1 will contain changes as revisions after comparison | |
DOC1.compare(DOC2, "user", date.today(), options) | |
if (DOC1.revisions.count > 0): | |
# Save resultant file as PDF | |
DOC1.save("compared.pdf", aw.SaveFormat.PDF) | |
else: | |
print("Documents are equal") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This code example demonstrates how to compare two PowerPoint presentation slides in Python | |
import aspose.slides as slides | |
with slides.Presentation("AccessSlides.pptx") as p1: | |
with slides.Presentation("HelloWorld.pptx") as p2: | |
for i in range(len(p1.masters)): | |
for j in range(len(p2.masters)): | |
if p1.masters[i] == p2.masters[j]: | |
print("Presentation1 MasterSlide#{0} is equal to Presentation2 MasterSlide#{1}".format(i,j)) | |
else: | |
print("Presentation1 MasterSlide#{0} is not equal to Presentation2 MasterSlide#{1}".format(i,j)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment