Document comparison tool

The requirement I have is to compare two documents(could be pdf to pdf, pdf to docx, docx to docx). I need a logic to compare the two files and display the original documents to be displayed side by side with the changes highlighted in the web application. I also require a side panel with the differences displayed in it.

How can Aspose help here to achieve this? Especially with the logic for highlighting in the document accurately.

@Likitha_T

Certainly, Aspose can help you achieve this by using our advanced document comparison capabilities. Here’s a step-by-step guide on how you can use Aspose products to compare documents and highlight differences:

Compare Documents with Aspose

1. Choose the Appropriate Aspose API

Depending on your file formats, you can use one of the following Aspose APIs:

  • Aspose.Words for .NET/Java: For comparing Word documents (DOCX).
  • Aspose.PDF for .NET/Java: For comparing PDF documents.
  • Aspose.Words for .NET/.Java: For comparing Word documents and can convert them to PDF for better visualization of differences.

2. Implement the Comparison Logic

Aspose.Words has built-in features to compare two documents and generate a result document that highlights the differences. Here is an example using Aspose.Words for .NET:

// Load two documents to compare
Document doc1 = new Document("input1.docx");
Document doc2 = new Document("input2.docx");

// Create comparison options
ComparisonSettings comparisonSettings = new ComparisonSettings();

// Compare documents and get the result document
Document comparedDocument = doc1.Compare(doc2, "Compared Output.docx", comparisonSettings);

// Save the result
comparedDocument.Save("compared-output.docx");

3. Display Documents Side by Side with Highlighted Changes

You can display the original and compared documents side by side using an appropriate web application. Aspose.Cells offers similar functionality, but for Excel files, while Aspose.Slides does the same for PowerPoint presentations.

4. Use Aspose.HTML to Convert and Display in Web

If you’re working with documents that you want to convert for better web visualization, you can use Aspose.HTML to convert them to HTML:

// Load the compared document
Document comparedDocument = new Document("compared-output.docx");

// Save as HTML
comparedDocument.Save("compared-output.html");

5. Implement a Side Panel for Differences

Display differences in a side panel by extracting the changes using Aspose APIs. Aspose.Words provides a way to access the revisions made during comparison:

public void PrintRevisions(Document doc)
{
    NodeCollection revisions = doc.GetChildNodes(NodeType.Revision, true);
    foreach (RevisedNode node in revisions)
    {
        Console.WriteLine($"Revision from {node.RevisionGroup.StartAuthor}: {node.RevisionGroup.Type}");
    }
}

6. Use Aspose for Web Applications

For a web application to display documents side by side with differences highlighted, you can use server-side code to generate the comparison document and client-side code to display it.

Example forSide Panel in Web Application

  • You can use JavaScript and HTML to read the changes made and show them in a side panel.

Reference Documentation

For detailed information on using Aspose for document comparison, refer to the following documentation:

Summary

By using Aspose products, you can achieve accurate comparison and highlight changes in various document formats. You can use Aspose.Words to compare documents, Aspose.PDF for PDF comparisons, and Aspose.HTML to convert documents for web display. For detailed implementation, refer to the provided documentation links.

But how will the highlighting be done accurately? Is there a way aspose can provide a way for me to achieve this?

@Likitha_T The question is already answered from Aspose.Words perspective here:
https://forum.aspose.com/t/how-can-i-get-the-coordinates-from-the-changes-detected-in-documents/316620/5

Is there a way to get it from Aspose.pdf perspective? Can someone from the Aspose.pdf team help with this?

@Likitha_T

An answer has already been posted in the original thread you opened earlier. You can please follow up there. ref: Comparison and fetching coordinates using aspose.pdf