Combine and Merge PDF files into One Online using Node.js

How to Combine and Merge PDF files into One Online using Node.js
Combine and Merge PDF files into One Online using Node.js

In certain cases, you may need to combine two or more PDF files. For example, you need to merge PDF files for creating documents using your previously created files for data referencing or when different users are working the same topic. Combining PDF files help you to keep your information consistent and make your documents more efficient. Today, we will learn how to combine and merge PDF files into one online using Node.js.

The following topics shall be covered in this article:

Online Document Merger REST API and Node.js SDK

To combine multiple PDF files, I will be using the Node.js SDK of GroupDocs.Merger Cloud API. It allows you to combine, extract, remove and rearrange a single page or a collection of pages from supported document formats such as Word, Excel, PowerPoint, Visio drawings, PDF, and HTML etc.

You can install GroupDocs.Merger cloud to your Node.js application using the following command in the console:

npm install groupdocs-merger-cloud

Please get your Client ID and Secret from the dashboard before following the mentioned steps. Once you have your ID and secret, add in the code as shown below:

Merge and Combine PDF files into One using Node.js

You can combine multiple PDF files into a single file programmatically on the cloud by following the simple steps given below:

  • Upload the PDF files to the cloud
  • Combine multiple PDF files using Node.js
  • Download the combined PDF Document

Upload the PDF Files

Firstly, upload the PDF files to the cloud using the code example given below:

As a result, the uploaded PDF files will be available in the files section of your dashboard on the cloud.

Merge Multiple PDF into One Online using Node.js

You can easily merge multiple PDF files into a single file programmatically by following the steps mentioned below:

  • Create an instance of the DocumentApi
  • Now, create the first JoinItem
  • Next, create the first item FileInfo
  • Provide the input file path for first JoinItem in the FileInfo
  • Create the second JoinItem
  • Create the second item FileInfo
  • Provide the input file path for second JoinItem in the FileInfo
  • Create the multiple files JoinOptions
  • Add comma separated list of created join items
  • Set the output file path
  • Create JoinRequest with JoinOptions as argument
  • Get results by calling the join() method of the DocumentAPI

The following code snippet shows how to merge multiple PDF files using REST API in Node.js:

Download Merge PDF Files

The above code sample will save the merged PDF file on the cloud. You can download it using the following code sample:

How to Merge Multiple PDF files Pages in Node.js

You can easily merge specific slides of multiple PDF files into a single file programmatically by following the steps mentioned below:

  • Firstly, create an instance of the DocumentApi
  • Next, create the first JoinItem
  • Now, create the first item FileInfo
  • Set the input file path for first JoinItem in the FileInfo
  • Provide comma separated list of pages to combine
  • Create the second JoinItem
  • Create the second item FileInfo
  • Set the input file path for second JoinItem in the FileInfo
  • Now, set startPageNumber value
  • next, set endPageNumber value
  • Create the multiple files JoinOptions
  • Add comma separated list of created join items
  • Set the output file path
  • Create JoinRequest with JoinOptions as argument
  • Get results by calling the join() method of the DocumentAPI

The following code snippet shows how to merge specific PDF files using REST API in Node.js:

Combine PDF files into One Online Free

Please try the following free online PDF merger tool, which is developed using the above API.

Conclusion

In this article, you have learned:

  • how to merge multiple PDF files into one PDF using Node.js;
  • how to merge specific pages of PDF files in Node.js using REST API;
  • programmatically upload PDF files and download the merged PDF file from the cloud;

The API also enables you to reorder or replace document pages, change page orientation, manage document passwords and perform other manipulations easily for any supported file format. It also provides .NET, Java, PHP, Ruby, Android, and Python SDKs as its document merger family members for the Cloud API. You can learn more about GroupDocs.Merge Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser.

Ask a question

You can ask your queries about how to combine PDF files, via our Free Support Forum

See Also