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

Free Support Forum - aspose.com

Convert HTML to Word & Create Comments (annotations) without Carriage Return or Line Break using C# .NET


I’m struggling with an issue to create comments without carriage return or line break.
Actually, I’m using an external library to annotate comments. While exporting my html to word I convert those annotations to Aspose word comments as follow:

var cssStyleRegex = new Regex(@"<annotation.*?>(.*?)<\/annotation>");
var match = cssStyleRegex.Match(contentXHTML);
if (match.Success)
    int commentId = 0;
    int endOfIndexPrevmatch = 0;
    int contentLength = contentXHTML.Length;
    foreach (Match m in cssStyleRegex.Matches(contentXHTML))
        XmlDocument doc = new XmlDocument();
        doc.XmlResolver = null;

        string annotationStr = m.Value;
        int indexMatch = m.Index;

        builder.InsertHtml(contentXHTML.Substring(endOfIndexPrevmatch, indexMatch - endOfIndexPrevmatch));

        Aspose.Words.Comment comment = new Aspose.Words.Comment(builder.Document);
        if (annotation.Comments.Count == 0)
            GetTextEditionTracking(builder, node.InnerXml);

        comment.Author = annotation.Comments[0].UserName;
        comment.DateTime = annotation.Comments[0].TimeConverted;
        comment.Initial = annotation.Comments[0].UserId;

        CommentRangeStart start = new commentRangeStart(builder.Document, comment.Id);

        // Insert some more text.
        GetTextEditionTracking(builder, node.InnerXml);
        // Insert end of comment range.
        CommentRangeEnd end = new CommentRangeEnd(builder.Document, comment.Id);


        // Insert comment and comment range start.

My goal is to avoid the carriage return inserted automatically before my comments.
This is an issue for text annotated in the middle of a sentence.

I’m using Aspose Words: for .Net.



Please ZIP and attach the following resources here for testing:

  • Your simplified source file
  • Aspose.Words for .NET 21.4 generated output file showing the undesired behavior
  • Your expected file showing the desired output. You can create this document manually by using MS Word.
  • Please also create a standalone simple 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 further investigation into your scenario and provide you more information.

Program.zip (3.0 KB)
TestAsposeWordComment.zip (127.3 KB)
You can find in attached file our source file “Program.cs” and the input XML file “ImportedFile”
and solution file “TestAsposeWordComment.zip”.
We are using Aspose Words : 20…9.0.0.



We are checking this scenario and will get back to you soon.

@wch, @amtalbi,

Please check Program Modified.zip (2.4 KB) which should help to achieve the desired output on your end.


Thank you for the program,

But we find an issue when we comment the same text many times.

ie : an exception is occurred when we comment the word “Confidential” two times with different comments

You can find attached a file where you will see an example.
ImportedFile.zip (1.3 KB)


We are checking this scenario and will get back to you soon.