Free Support Forum - aspose.com

How to split paragraph

What is the most efficient way in Aspose.Words to split a Word paragraph into two paragraphs, while retaining all formatting?

If I simply add a “\r\n” into the text of a run within the paragraph, only a soft return is added. Do I need to create a new paragraph object and then copy in the Run objects one by one from the previous paragraph, deleting them one by one in the previous paragraph?

Hi Avi,

Thanks for your inquiry. In your case, I suggest you please use DocumentBuilder.InsertBreak method with BreakType ParagraphBreak. The following code example shows how to insert Paragraph Break after a run node.

Document doc = new Document(MyDir + "in.docx");

DocumentBuilder builder = new DocumentBuilder(doc);

//Move cursor to first paragraph's 3rd run node.

builder.MoveTo(doc.FirstSection.Body.FirstParagraph.Runs[4]);

builder.InsertBreak(BreakType.ParagraphBreak);

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