How to Copy Pages from One PDF Into Another using Node.js
Manipulating multiple PDF documents in a web application might seem complex, but with the right API, it’s extremely straightforward.

With the below code, you can take advantage of a free API which allows you to target a subset of pages in one uploaded PDF document and copy those pages into another uploaded PDF document. You can specify exactly where the pages should be entered, too.
All the code you’ll need is provided below. You can start by installing the SDK — either by running the following command:
npm install cloudmersive-convert-api-client --save
Or by adding the following snippet to your package.json:
"dependencies": {
"cloudmersive-convert-api-client": "^2.6.3"
}
Next, you can obtain a free-tier API key to authorize your requests by registering a free account on the Cloudmersive website. This allows a limit of up to 800 API calls per month with no additional commitment.
You can then copy the below ready-to-run code examples to structure your API call:
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.EditPdfApi();
var sourceFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Source PDF file to copy pages from.
var destinationFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Destination PDF file to copy pages into.
var pageStartSource = 56; // Number | Page number (1 based) to start copying pages from (inclusive) in the Source file.
var pageEndSource = 56; // Number | Page number (1 based) to stop copying pages pages from (inclusive) in the Source file.
var pageInsertBeforeDesitnation = 56; // Number | Page number (1 based) to insert the pages before in the Destination file.
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.editPdfInsertPages(sourceFile, destinationFile, pageStartSource, pageEndSource, pageInsertBeforeDesitnation, callback);
That’s all there is to it — no more code required!