Merge Word files

In large distributed enterprises, many people work on certain modules of a large application or in various departments that produce a unified/merged product and during the development process, they continue to work on living product documentation. For long-term document archival, we combine documents so that a single document can be stored. In the rest of the article, we are going to explain details on how to merge word files.

Manual Approach

MS Word provides the feature to open/access multiple Word documents so that their pages can be combined. But in case there are numerous files (more than a hundred or thousand etc), it gets difficult to open each document and merge them manually. Therefore, you need some utility to combine the files in a bulk. However, in this scenario, there needs to be a person who shall manually use the utility. But in case, we have to programmatically accomplish this requirement, we need a document manipulation that can handle popular Word documents.

On-premise or Cloud API?

Aspose is a leading brand in file format processing with success stories spanning over decades where more than 77% of Fortune 100 companies trust Aspose APIs for their document processing requirements. It offers the Word document processing solution both in the form of On-Premise (Aspose.Words Product family) and Cloud solutions (Aspose.Words Cloud product family). This article is more towards Cloud APIs and you do not need to install anything. Use Desktop or Mobile platforms and accomplish your requirements. Simply make calls to APIs and get your desired operations accomplished.

Supported file formats

Its capable of loading popular MS Word file formats including DOC, DOCX, RTF, DOT, DOTX, DOTM, FlatOPC (XML), OpenOffice ODT, OTT, WordprocessingML(XML), Web (HTML, MHTML, HtmlFixed), TXT and PDF formats.

Another remarkable feature of Aspose.Words Cloud API is that it offers you the flexibility to save the output in input word format or you can choose to render the resultant file in PDF, PS, XPS, OpenXPS, PNG, JPEG, BMP, SVG, TIFF, EMF, PCL, EPUB formats. Use the cURL commands over the command prompt to accomplish your requirements. Or, you may use any language of your choice and use a couple of code lines to perform required operations.

cURL command

The cURL commands are the easiest way to call Cloud APIs and since our APIs are only accessible to authorized people, so you need to first signup on website where you will find your personalized Client ID and Client Secret. They both are required when you obtain a JWT authorization token, which is necessary when using cURL commands for accessing the Cloud APIs. Please visit the following article for details on how to obtain JSON Web Token Authentication.

Once you have the JWT token, use the following cURL command to perform the document merge operation. You may also download and explore sample input test_doc.docx, test_multi_pages.docx, and the resultant test_doc_output.docx files.

curl -X PUT "" \
-H "accept: application/json" \
-H "Authorization: Bearer <JWT Token>" \
-H "Content-Type: application/json" \
-d "{\"DocumentEntries\":[{\"Href\":\"test_multi_pages.docx\",\"ImportFormatMode\":\"KeepSourceFormatting\"}],\"ApplyBaseDocumentHeadersAndFootersToAppendingDocuments\":true}"

Java API

The document merge operation can also be accomplished using Aspose.Words Cloud Java SDK.

  • First of all, create an object of WordsApi class
  • Secondly, set the Client Secret and Client ID for WordsApi object
  • Then we need to create an instance of DocumentEntry which will define the list of files to be merged and the formatting for the resultant document
  • Later on, create an object of DocumentEntryList and specify the list of documents to be appended
  • Penultimate, create an instance of AppendDocumentRequest class which holds the arguments for source file, DocumentEntryList to be merged, name of the resultant merged document, folder, storage, etc details
  • Finally, initialize an object of DocumentResponse class and call appendDocument(..) method to perform the document merge operation

Conclusion statement

The article has explained the steps to merge Word documents into a single unified document using the cURL command or Java code snippet. In case you have any related query, please feel free to contact via Aspose.Words Free support forum.

You may consider visiting the following link for related details on