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

Free Support Forum - aspose.com

How to insert a new paragraph in Builder

Hi,
I am trying to insert a new paragraph using builder but its carry forwarding it’s previous formatting to new paragraph.
However I am not sure how to insert a brand new paragraph using ‘Paragraph para = new Paragraph(doc);’ to a certain position in builder?

Hi Pradeep,

Thanks for your inquiry. Please use the following documentation links for your kind reference.
http://www.aspose.com/docs/display/wordsnet/DocumentBuilder+Overview
http://www.aspose.com/docs/display/wordsnet/Moving+the+Cursor
http://www.aspose.com/docs/display/wordsnet/Inserting+Document+Elements#InsertingDocumentElements-paragraph

Please use Font.ClearFormatting and ParagraphFormat.ClearFormatting before inserting new paragraph with default font formatting. See the following highlighted code snippet.


Document
doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

// Specify font formatting

Aspose.Words.Font font = builder.Font;

font.Size = 16;

font.Bold = true;

font.Color = System.Drawing.Color.Blue;

font.Name = "Arial";

font.Underline = Underline.Dash;

// Specify paragraph formatting

ParagraphFormat paragraphFormat = builder.ParagraphFormat;

paragraphFormat.FirstLineIndent = 8;

paragraphFormat.Alignment = ParagraphAlignment.Justify;

paragraphFormat.KeepTogether = true;

builder.Writeln("A whole paragraph.");

builder.Font.ClearFormatting();

builder.ParagraphFormat.ClearFormatting();

builder.Writeln();

builder.InsertParagraph();

builder.InsertBreak(BreakType.ParagraphBreak);

doc.Save(MyDir + "Out.docx");