Merger

Wordize Merge for .NET combines your documents into one, saving time and reducing manual work. Merge documents, preserving styles and choosing a convenient output document format.

Wordize provides the Wordize Merge for .NET module to combine multiple documents into one, saving time and reducing manual work. Programmatically merging documents ensures consistent formatting, supports various output formats (e.g. DOCX, PDF), and enhances document management. It is especially useful for creating reports, consolidating legal documents, and handling large-scale data efficiently.

How to Merge Documents

Merging documents appends the second document to the end of the first. Use one of the following Merge methods to programmatically merge two documents:

  • Merge(string, string[])
  • Merge(string, string[], SaveFormat, MergeFormatMode)
  • Merge(Stream, Stream[], SaveFormat)

How to Specify Output Document Formatting

You can also specify how formatting is merged when combining multiple documents using the MergeFormatMode enumeration:

  • MergeFormatting — to combine document formatting.
  • KeepSourceFormatting — to retain source documents’ formatting
  • KeepSourceLayout — to preserve source documents’ layout

Document Merge Examples

The following code example shows how to merge two documents into one using the Merge(string, string[]) method:

string inputDoc1 = MyDir + "Document1.docx";
string inputDoc2 = MyDir + "Document2.docx";

Merger.Merge(ArtifactsDir + "MergeDocument.1.docx", new[] { inputDoc1, inputDoc2 });

The following code example shows how to merge two documents into one, preserving source documents’ layout and using the Merge(string, string[], SaveFormat, MergeFormatMode) method:

string inputDoc1 = MyDir + "Document1.docx";
string inputDoc2 = MyDir + "Document2.docx";

Merger.Merge(ArtifactsDir + "MergeDocument.2.pdf", new[] { inputDoc1, inputDoc2 }, SaveFormat.Pdf, MergeFormatMode.KeepSourceLayout);

The following code example shows how to merge two documents into one, specifying a save format and using the Merge(Stream, Stream[], SaveFormat) method:

using (FileStream firstStreamIn = new FileStream(MyDir + "Document1.docx", FileMode.Open, FileAccess.Read))
{
    using (FileStream secondStreamIn = new FileStream(MyDir + "Document1.docx", FileMode.Open, FileAccess.Read))
    {
using (FileStream streamOut = new FileStream(ArtifactsDir + "MergeStreamDocument.1.docx", FileMode.Create, FileAccess.ReadWrite))
            Merger.Merge(streamOut, new[] { firstStreamIn, secondStreamIn }, SaveFormat.Docx);
	}
}