How to Merge Two Word Documents in Node.JS

Cloudmersive
Nov 3, 2020

--

When creating long-format documents like contracts or manuals, your greatest resource is your library of documents that has already been created. Rather than copying and pasting entire pages from one document into another, merging the documents will take less time and hassle. This API will allow you to instantly merge two DOCX documents together. The parameters for this function include the two input files you would like to merge. Note that more than two files can be merged by adding more input file lines.

To run the API, use this command to install the SDK:

npm install cloudmersive-convert-api-client --save

Or, you can add this snippet to your package.json:

"dependencies": {
"cloudmersive-convert-api-client": "^2.4.8"
}

Then, you can call the function:

var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveConvertApiClient.MergeDocumentApi();var inputFile1 = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | First input file to perform the operation on.var inputFile2 = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Second input file to perform the operation on (more than 2 can be supplied).var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.mergeDocumentDocx(inputFile1, inputFile2, callback);

You can retrieve the API Key for this function at no cost and with no commitment on the Cloudmersive website. This will give you access to 800 monthly calls across our entire API library.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet