This topic shows how to use the JoinDocx plugin to merge Word documents in the DOCX format. JoinDocx takes a source DOCX document and appends other DOCX documents to it, in the order you list them.
Prerequisites
Refer to the Developer Guide to learn how to set up your environment and run the code examples in this section.
The following example appends the second chapter of a business plan to the first one. The documents are loaded from the current folder, and the merged document is saved to the output folder.
usingSystem;usingGroupDocs.Merger.Domain.Options;usingGroupDocs.Merger.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply the licenseLicense.Set(publicKey,privateKey);// Append the documents to the source documentvarmerger=newJoinDocx("chapter-1.docx",new[]{"chapter-2.docx"},newJoinOptions());// Save the merged documentmerger.Save("output/chapters-1-2.docx");
ImportsSystemImportsGroupDocs.Merger.Domain.OptionsImportsGroupDocs.Merger.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply the license
License.Set(publicKey,privateKey)' Append the documents to the source document
DimmergerAsNewJoinDocx("chapter-1.docx",{"chapter-2.docx"},NewJoinOptions())' Save the merged document
merger.Save("output/chapters-1-2.docx")EndSubEndModule
openSystemopenGroupDocs.Merger.Domain.OptionsopenGroupDocs.Merger.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply the license
License.Set(publicKey,privateKey)// Append the documents to the source document
letmerger=JoinDocx("chapter-1.docx",["chapter-2.docx"],JoinOptions())// Save the merged document
merger.Save("output/chapters-1-2.docx")0
Pass as many documents as you need. They are appended to the source document in the order of the list. The following example merges three chapters into one document.
usingSystem;usingGroupDocs.Merger.Domain.Options;usingGroupDocs.Merger.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply the licenseLicense.Set(publicKey,privateKey);// Append the documents to the source documentvarmerger=newJoinDocx("chapter-1.docx",new[]{"chapter-2.docx","chapter-3.docx"},newJoinOptions());// Save the merged documentmerger.Save("output/merged-chapters.docx");
ImportsSystemImportsGroupDocs.Merger.Domain.OptionsImportsGroupDocs.Merger.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply the license
License.Set(publicKey,privateKey)' Append the documents to the source document
DimmergerAsNewJoinDocx("chapter-1.docx",{"chapter-2.docx","chapter-3.docx"},NewJoinOptions())' Save the merged document
merger.Save("output/merged-chapters.docx")EndSubEndModule
openSystemopenGroupDocs.Merger.Domain.OptionsopenGroupDocs.Merger.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply the license
License.Set(publicKey,privateKey)// Append the documents to the source document
letmerger=JoinDocx("chapter-1.docx",["chapter-2.docx";"chapter-3.docx"],JoinOptions())// Save the merged document
merger.Save("output/merged-chapters.docx")0
The source document can also be a Stream; the documents to append are always file paths. The stream is read from the beginning, and it stays open after Save.
usingSystem;usingSystem.IO;usingGroupDocs.Merger.Domain.Options;usingGroupDocs.Merger.LowCode;// Load license keysvarpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY");varprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY");// Apply the licenseLicense.Set(publicKey,privateKey);// Open the source document as a streamusingvarstream=File.OpenRead("chapter-1.docx");// Append the documents to the source documentvarmerger=newJoinDocx(stream,new[]{"chapter-2.docx"},newJoinOptions());// Save the merged documentmerger.Save("output/chapters-1-2.docx");
ImportsSystemImportsSystem.IOImportsGroupDocs.Merger.Domain.OptionsImportsGroupDocs.Merger.LowCodeModuleProgramSubMain()' Load license keys
DimpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")DimprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")' Apply the license
License.Set(publicKey,privateKey)' Open the source document as a stream
Usingstream=File.OpenRead("chapter-1.docx")' Append the documents to the source document
DimmergerAsNewJoinDocx(stream,{"chapter-2.docx"},NewJoinOptions())' Save the merged document
merger.Save("output/chapters-1-2.docx")EndUsingEndSubEndModule
openSystemopenSystem.IOopenGroupDocs.Merger.Domain.OptionsopenGroupDocs.Merger.LowCode[<EntryPoint>]letmain_=// Load license keys
letpublicKey=Environment.GetEnvironmentVariable("GD_PUBLIC_KEY")letprivateKey=Environment.GetEnvironmentVariable("GD_PRIVATE_KEY")// Apply the license
License.Set(publicKey,privateKey)// Open the source document as a stream
usestream=File.OpenRead("chapter-1.docx")// Append the documents to the source document
letmerger=JoinDocx(stream,["chapter-2.docx"],JoinOptions())// Save the merged document
merger.Save("output/chapters-1-2.docx")0