Blank lines removed from the word object


We using DocumentBuilder to do some manipulation and during that we loosing some blank rows. I am attaching sample code to show you the problem. Document appears fine when “Show paragraph marks and other hidden formatting symbols.” is enabled in MS word .

Please run the program and click/un click on Show paragraph marks and other hidden formatting symbols on generated file “output2.docx”

Hi Meet,

Thanks for your inquiry. Please set Font.Hidden as false as shown in following highlighted code snippet to get the correct output. Hope this helps you.

Document mainDocument = new Document(MyDir + "t14.docx");
var bookmark = mainDocument.Range.Bookmarks.Cast<Bookmark>().First();
if (bookmark == null)
DocumentBuilder builder = new DocumentBuilder(mainDocument);
var paragraphs = GetIncludedParagraphs(bookmark);
foreach (Paragraph para in paragraphs)
    bool hasChildNodes = para.HasChildNodes;
    builder.MoveTo(hasChildNodes ? para.FirstChild : para);
    // Insert the temporary page field used to gather the page number at node.
    // Format the field it as hidden so the field does not affect the layout of the document.
    builder.Font.Hidden = true;
    var fieldStart = builder.InsertField(Page, One);
    // Repeat for the end of the node as some nodes can span over more than one page.
    if (hasChildNodes)
        builder.Font.Hidden = true;
        builder.InsertField(Page, One);
    builder.Font.Hidden = false;
builder.Document.Save(MyDir + "Out.docx");