We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Document Comparison

Hi. I am trying to compare 2 documents, save the changes to docx and pdf, and also a simple XML file that lists the change and some surrounding text, plus original text prior to the change. Is there a way to do this? Here is some code I’ve written in vb. OriginalText always seems to be the entire document:

        Dim co As New CompareOptions()
        co.IgnoreFormatting = req.WhiteSpace
        co.IgnoreHeadersAndFooters = False
        co.IgnoreCaseChanges = False
        co.IgnoreComments = req.ComparisonType.ToLower.Contains("no annotation")
        co.IgnoreFootnotes = False
        co.IgnoreTables = req.IgnoreTables
        co.IgnoreTextboxes = True

        'ComparisonTargetType with IgnoreFormatting setting determines which document has to be used as formatting source for ranges of equal text.
        Doc1.Compare(Doc2, "junk", DateTime.Now, co)

        'If doc1 And doc2 are different, doc1 now has some revisions after the comparison, which can now be viewed And processed.
        If req.AutoRev Then 'generate XML of revisions
            'Dim rev As Revision
            Dim writer As New XmlTextWriter(sFilePath & "\" & "CompareDetail.xml", System.Text.Encoding.UTF8)
            writer.Formatting = System.Xml.Formatting.Indented
            writer.Indentation = 2


            Dim cloneDoc As Aspose.Words.Document = Doc1.Clone(True)

            Dim removerevision As ArrayList = New ArrayList()

            For Each rev As Revision In cloneDoc.Revisions
                If rev.ParentNode.NodeType = NodeType.Run And rev.RevisionType = RevisionType.Insertion Then

                End If

            For Each revision As Revision In removerevision

            For Each item As Revision In cloneDoc.Revisions

                Dim p As Node = item.ParentNode.ParentNode

                If p IsNot Nothing Then
                    Dim body As Node = p.ParentNode

                    If body IsNot Nothing Then
                        Dim originaltext As String = p.ToString(SaveFormat.Text)
                        Dim newtext As String = item.ParentNode.ToString(SaveFormat.Text)



                        writer.WriteEndElement() 'OriginalText

                        writer.WriteEndElement() 'RevisionText

                        writer.WriteEndElement() 'Revision

                    End If

                End If
            writer.WriteEndElement() 'Revisions


To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input documents
  • Aspose.Words 19.8 generated output document showing the undesired behavior
  • Your expected document showing the correct output. You can create expected document by using MS Word.
  • Please also create a simplified standalone console application (source code without compilation errors) that helps us to reproduce your current problem on our end and attach it here for testing. Please do not include Aspose.Words DLL files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.