How to Merge Two PDF Files in Node.JS
Working with large documents can be time-consuming and stressful. One bad keystroke can eliminate all of you work in an instant, and incorrect formatting may mean that your document looks pieced together and unprofessional. By merging your PDF documents together to create a larger document, you can minimize your time spent on the task and maximize the quality of the output. The following API will allow you to merge two or more PDF files into one, preserving the order of the input documents once combined.
You can use this API by running the following 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.mergeDocumentPdf(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.