We have an application that combines multiple documents into a single document. I have a situation where First.docx is a numbered list, with no hard returns or content after the last character of the last list item. I then take Second.docx, insert a BreakType.SectionBreakNewPage because I want the next document to be on a new page, and then import the content of the second document.
Hi Matt,
Thanks for your inquiry. In your case, I suggest you please use the Document.AppendDocument method to append the specified document to the end of this document. Please use the following code examples to achieve your requirements.
Hope this helps you. Please let us know if you have any more queries.
var wordSubdoc = new Document(MyDir + @"First.docx");
var docB = new Document(MyDir + @"Second.docx");
// Set the appended document to appear on a new page.
docB.FirstSection.PageSetup.SectionStart = SectionStart.NewPage;
wordSubdoc.AppendDocument(docB, ImportFormatMode.KeepSourceFormatting);
wordSubdoc.Save(MyDir + "result.docx");
var wordSubdoc = new Document(MyDir + @"First.docx");
var builder = new DocumentBuilder(wordSubdoc);
builder.MoveToDocumentEnd();
builder.InsertBreak(BreakType.SectionBreakNewPage);
builder.MoveToDocumentEnd();
//builder.ListFormat.RemoveNumbers();
builder.ParagraphFormat.ClearFormatting();
var body = wordSubdoc.LastSection.Body;
var lastNode = body.LastChild;
var docB = new Document(MyDir + @"Second.docx");
foreach (Section section in docB.Sections)
{
foreach (Node node in section.Body)
{
var importedNode = wordSubdoc.ImportNode(node, true);
body.InsertAfter(importedNode, lastNode);
lastNode = importedNode;
}
}
wordSubdoc.Save(MyDir + "result.docx");