facebooktwittermenuarrow-up

GemBox Support Forum

How we can add new paragraph after any paragraph

How we can add new paragraph after any paragraph In existing word documents.

Hi,

Try this:

var document = DocumentModel.Load("input.docx");

// Get second paragraph.
var paragraph = document.Sections[0].GetChildElements(false, ElementType.Paragraph)
    .Cast<Paragraph>()
    .ElementAt(1);

// Add paragraph after it.
int index = paragraph.ParentCollection.IndexOf(paragraph);
paragraph.ParentCollection.Insert(index + 1,
    new Paragraph(document, "New paragraph."));

document.Save("output.docx");

I hope this helps.

Regards,
Mario

Thanks for you your help my issue was resolved now.