Free Support Forum - aspose.com

Merge docx documents

Is there a way to merge multiple docx documents into one document iwth ASPOSE. I know we have merge but not sure that works.

Hi Jon,

Thanks for your inquiry. You can merge documents by using Document.AppendDocument Method. Please read following documentation links for your kind reference

Appending Documents Overview
Join a Document onto another Document
How the AppendDocument Method Works
Differences between ImportFormat Modes
How to Insert a Document into another Document

Please check the following code snippet for your kind reference.

// The document that the content will be appended to.

Document dstDoc = new Document(MyDir + "Document.doc");

// The document to append.

Document srcDoc = new Document(MyDir + "DocumentBuilder.doc");

// Append the source document to the destination document.

// Pass format mode to retain the original formatting of the source document when importing it.

dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);

// Save the document.

dstDoc.Save(MyDir + "Document.AppendDocument Out.doc");


Please let us know if you have any more queries.

tahir.manzoor:
Hi Jon,

Thanks for your inquiry. You can merge documents by using Document.AppendDocument Method. Please read following documentation links for your kind reference


Please check the following code snippet for your kind reference.

// The document that the content will be appended to.<?xml:namespace prefix = o />

Document dstDoc = new Document(MyDir + "Document.doc");

// The document to append.

Document srcDoc = new Document(MyDir + "DocumentBuilder.doc");

// Append the source document to the destination document.

// Pass format mode to retain the original formatting of the source document when importing it.

dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);

// Save the document.

dstDoc.Save(MyDir + "Document.AppendDocument Out.doc");


Please let us know if you have any more queries.

This is great Thanks. One thing, it's merging it at the end of the previous document. Is there a way I can have the second document start on a new page or insert a page break before Appending.

Thanks,

JT

Hi Jon,


Thanks for your inquiry. Yes, you can insert page break before appending document by using DocumentBuilder.InsertBreak method. Please read following documentation links for your kind reference.

http://www.aspose.com/docs/display/wordsnet/BreakType+Enumeration
http://www.aspose.com/docs/display/wordsnet/DocumentBuilder+Overview


<span lang=“EN-GB” style=“font-family:“Courier New”;color:#2B91AF;mso-no-proof:yes”>DocumentBuilder<span lang=“EN-GB” style=“font-family:“Courier New”;mso-no-proof:yes”> builder = new DocumentBuilder(dstDoc);<o:p></o:p>

builder.InsertBreak(BreakType.PageBreak);

dstDoc.AppendDocument(srcDoc, ImportFormatMode.KeepSourceFormatting);

Please let us know if you have any more queries.