The replies order in Word comments

Dear Sir or Madam,

In our document we have “paragraphs” and “tables”. When I try to insert the comments in the paragraphs, the order is the same as I add them. When I add a comment to a table it reverses it. In the attached document I added #1, #2,#3,#4,#5 , the code is this:

private void AddComment(AW.Paragraph para, WordComment wordComment)
{
    Comment comment = new Comment(mOutputDocument);
    comment.SetText(wordComment.Comments[0].Text ?? string.Empty);
    comment.Author = wordComment.Comments[0].Name;
    para.AppendChild(comment);
    for (int i = 1; i < wordComment.Comments.Count; i++)
    {
        SingleComment c = wordComment.Comments[i];
        comment.AddReply(c.Name, string.Empty, c.Date, c.Text ?? string.Empty);
    }
    comment.Done = wordComment.IsResolved;
}

Basically setting the string 0 (#1) as a main comment, and all others as consequent replies. Still the result is different. Is there anything you could suggest to me to look into?

Thank you in advance,
Alex_Alex test-Operating segments-_Alex test-TOC-Suffix (11).docx (19.1 KB)

@AlexanderNovickov I was unable to reproduce the issue you mentioned.

Document doc = new Document("IssueClean.docx");
// Comment in root table.
Paragraph para = doc.FirstSection.Body.GetChild(NodeType.Paragraph, 5, true) as Paragraph;
Comment comment = new Comment(doc);
comment.SetText("#1");
comment.Author = "Author1";
para.AppendChild(comment);
for (int i = 2; i < 5; i++)
    comment.AddReply("Author1", string.Empty, DateTime.Now, "#" + i);
comment.Done = false;
// Comment in nested table.
para = doc.FirstSection.Body.GetChild(NodeType.Paragraph, 12, true) as Paragraph;
comment = new Comment(doc);
comment.SetText("#1");
comment.Author = "Author1";
para.AppendChild(comment);
for (int i = 2; i < 5; i++)
    comment.AddReply("Author1", string.Empty, DateTime.Now, "#" + i);
comment.Done = false;
doc.Save("IssueOut.docx");

Perhaps the reason lies in the calling code.
Could you provide this code? We will check the issue and provide you more information.

IssueClean.docx (22.8 KB)
IssueOut.png (64.5 KB)

Hi Victor,

I’ll try to reproduce it on a lean document, but even in my original code the issue happens only then I try to insert it in the table (see the screenshot) and you insert it in the paragraph above the table.Screenshot 2022-06-01 213851.png (113.7 KB)

In all the cases in your code the comment is inserted in the paragraph that is located in the table cell. In the first and in the third cases this is the root table, in the second and in the fourth one this is the nested table. It is not possible to insert the comment directly into the table. I have additionally tested my code mentioned above with all the paragraphs, from 12 to 32, that are in the nested table, and none of these cases result in the output you specified.
The code you provide does not contain the description and content of WordComment and SingleComment classes, so it is impossible for us to fully test your case. Replacing their contents by constant values ​​does not reproduce the issue.

Hi Vadim,

I have tailored our project to some kind of a minimum enough to demonstrate my issue. The code creates a wrapper table and then inserts into it a table with a header and a body. First cells of both header and body have comments (added via BuildAndAddComment). In the body comment the order of replies is correct, in the header one it’s reversed. Could you please let me know why is it happening and how it can be fixed?

Thank you in advance,
AlexConsoleApp1.zip (5.2 KB)

@AlexanderNovickov Thank you for additional information. I have reproduced and logged the issue as WORDSNET-23936. We will keep you informed and let you know once it has been resolved.
I suggest you the following code as a workaround while the issue is being fixed. Please accept our apologies for your inconvenience.

public void BuildTable()
{
  Cell[] wrapCells = AppendWrapperRow(1);
  Cell contentWrapCell = wrapCells[0];
  Table awTable = new Table(mOutputDocument);
  contentWrapCell.AppendChild(awTable); // <---
  int columnsCount = 5;
  
  // Build header.
  BuildHeader(awTable);

  //---> contentWrapCell.AppendChild(awTable);
  ...
}

Hi Viktor,

Works like a charm, thank you, much appreciated.

Alex

Actually, one more question. When I save to the Word it shows correctly the name of the author (Alex), if I use the same code and save the final document into pdf it doesn’t show the author. Is there a way to force PDF to show “Alex” as author in PDF?

AlexIssueClean1.pdf (39.6 KB)

@AlexanderNovickov If you execute in MS Word: File -> Print, or save the specified document in Pdf using MS Word, you will see that MS Word output is exactly the same as that of Aspose.Words. Aspose.Words copies exactly MS Word output, not the editor visual display. However, you can see “Author” value in the output Pdf if you export to Pdf in the specified manner.

doc.LayoutOptions.CommentDisplayMode = CommentDisplayMode.ShowInAnnotations;

In this case, again, there will be no display similar to that of MS Word editor.

Hi Victor, once again, thank you for a prompt reply, I totally understand that PDF as a docx document is produced from the same aspose tree, and I probably put my question wrong. Please look into attach. There is a word document I created in Ms Word editor and published as PDF. The comments structure is totally different from the one produced by Aspose. First, it has initials in every comment “AN”. Second, the Aspose’s PDF shows all the comments as replies to the comment 2 (2R2, 3R2 etc) whereas the one from the Word editor correctly shows them as the replies to the comment 1 ([AN2R1], [AN3R1]). So my question would be: how do I need to update my code to produce the aspose document, which would give the author’s initials and the correct comments numbering in PDF?
Thank you in advance,
AlexTest.zip (59.2 KB)
Screenshot 2022-06-07 081439.png (45.4 KB)

Hi Victor, please ignore the part of the question regarding the initials, I noticed I didn’t add it into my sample project, sorry. Still I wonder how the replies numbering could be fixed?

Regards,
Alex

@AlexanderNovickov Unfortunately, I was still unable to reproduce the difference in Pdf output display.
As an input document I take the last “Test.docx” you have sent me. I save it in MS Word in pdf format under the name “TestWord.pdf”, then I export it to pdf using Aspose.Words, and I finally get “Test_aspose.pdf” as an output. I am attaching the output screenshot. As you can see, the outputs are identical.
Screen.png (61.2 KB)

Replies to the comment are added in reverse order if the Paragraph with the root comment anchor added has been created but has not yet been added to the document tree.

Document doc = new Document();
// Para on the air.
Paragraph para = new Paragraph(doc);
// Let's add comments.
Comment comment = new Comment(doc);
comment.SetText("#0");
comment.Author = "Author";
para.AppendChild(comment);
for (int i = 1; i < 3; i++)
  comment.AddReply("Author", string.Empty, DateTime.Now, "#" + i);

// Para in the tree.
doc.FirstSection.Body.Paragraphs.Add(para);
// Lets once again.
comment = new Comment(doc);
comment.SetText("#0");
comment.Author = "Author";
para.AppendChild(comment);
for (int i = 1; i < 3; i++)
  comment.AddReply("Author", string.Empty, DateTime.Now, "#" + i);

doc.Save("out.docx");

Our developers are working on the fix for this issue. We will keep you informed and let you know once it is resolved.

Hi Victor,

Thank you for your reply, but I don’t think are on the same page here. Yes, I understand when the reverse insertion happens and thank you for the workaround, it perfectly works. My question is not about inverting. If you produce the pdf using the project attached, the replies in PDF will be like:
[AA2R2]:
[AA3R2]:
[AA4R2]:
[AA5R2]:

meaning all of them are replies to the comment #2 and I would expect them to be
[AA2R1]:
[AA3R1]:
[AA4R1]:
[AA5R1]:
because actually they are replies to the comment #1.
Regards,
Alex
Comments.zip (9.9 MB)

@AlexanderNovickov Thank you for additional information. I have logged issue as WORDSNET-23950. We will keep you informed and let you know once it is resolved.

The issues you have found earlier (filed as WORDSNET-23936,WORDSNET-23950) have been fixed in this Aspose.Words for .NET 22.7 update also available on NuGet.