How to remove extra paragraph at the start of document using .NET

Below are the codes:

Document fullDocument = new Document();
DocumentBuilder builder = new DocumentBuilder(fullDocument);
            
ParagraphFormat paragraphFormat = builder.ParagraphFormat;
paragraphFormat.LineSpacingRule = LineSpacingRule.Multiple;
paragraphFormat.LineSpacing = 18.0;

var firstParagraph = builder.InsertParagraph();
var nameTitleRun = new Run(fullDocument, "Name of Journal: ");
nameTitleRun.Font.Bold = true;
nameTitleRun.Font.Name = defaultFontName;
firstParagraph.AppendChild(nameTitleRun);

But in the word file, there’s an extra paragraph break before the first paragraph, so my question is how to remove it? Thanks.

20200720220835.png (1.8 KB)

@mavercloud

Please note that a valid empty document has one paragraph in the document. The DocumentBuilder.InsertParagraph inserts one more paragraph into document.

You can use following code example to get the desired output.

Document fullDocument = new Document();
DocumentBuilder builder = new DocumentBuilder(fullDocument);

ParagraphFormat paragraphFormat = builder.ParagraphFormat;
paragraphFormat.LineSpacingRule = LineSpacingRule.Multiple;
paragraphFormat.LineSpacing = 18.0;

var firstParagraph = fullDocument.FirstSection.Body.FirstParagraph;
var nameTitleRun = new Run(fullDocument, "Name of Journal: ");
nameTitleRun.Font.Bold = true;
nameTitleRun.Font.Name = "Arial";
firstParagraph.AppendChild(nameTitleRun);

fullDocument.Save(MyDir + "out.docx");