Need Help on getting the paragraph Id's for the revision w.r.t document structure

I need to compare two documents from Base64Encodedstring and need to present the revision results in the given json format.

Here is my code for the same

// Step 1: Decode the Base64-encoded strings to obtain the content of the documents.
byte[] base64DecodedBytes1 = Convert.FromBase64String(documentComparePostDataBindingModel.Ooxml1);
byte[] base64DecodedBytes2 = Convert.FromBase64String(documentComparePostDataBindingModel.Ooxml2);

// Step 2: Load the content of the documents using Aspose.Words.
Document doc1 = new(new MemoryStream(base64DecodedBytes1));
Document doc2 = new(new MemoryStream(base64DecodedBytes2));
CompareOptions options = new();

// Step 3: Compare the two documents using Aspose.Words' comparison features.
doc1.Compare(doc2, "Thiyagarajan Narayanan", DateTime.Now, options);

// Step 4: Generate the output in the proposed format.
List<DocumentCompareResponseDataBindingModel> docResponses = new();

foreach (Revision revision in doc1.Revisions)
    // Find the paragraph containing the revision and its text content
    Paragraph paragraph = FindParagraphContainingRevision(doc1, revision);
    if (paragraph != null)
        string textContent = paragraph.GetText();

        // Find the start range of the text content within the whole document
        int startRange = doc1.GetText().IndexOf(textContent);
        int endRange = startRange + textContent.Length;

        DocumentCompareResponseDataBindingModel responseItem = new DocumentCompareResponseDataBindingModel
            // Pid = paragraph.ParagraphFormat.ListLabel.LabelValue,
            Inserted = revision.RevisionType == RevisionType.Insertion,
            Substituted = revision.RevisionType == RevisionType.FormatChange,
            Repealed = revision.RevisionType == RevisionType.Deletion,
            StartRange = startRange,
            EndRange = endRange,
var jsonString = JsonConvert.SerializeObject(docResponses);
JObject jObject = JObject.Parse(jsonString);
return Task.FromResult(jObject);

The issue I am facing here is getting the paragraph Id’s. It seems no direct way to fetch the paragraph numbers. Any workaround will be helpful. Please help on this.

@coderthiyagarajan1980 Aspose.Words does not provide access to paraId attribute. The value is dynamic and can be changed after document processing. If you need to identify the paragraphs while the document object lifetime, you can consider using Node.CustomNodeId. But note, specified value of this property is not saved to an output file and exists only during the node lifetime.

Thanks My issue is resolved.

1 Like