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

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

Sometimes we may need to combine two or more PDF files to make a more complete one. 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 on the same topic. Combining PDF files help you to keep your information consistent and make your documents more efficient. It can be tedious to manually copy and paste content or import content from other documents to merge documents. Therefore, we will learn how to combine and merge PDF files into one online using Node.js REST API.

This article will cover the following topics.

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.

The following command in the console will enable GroupDocs.Merger cloud for your Node.js application:

npm install groupdocs-merger-cloud

Please obtain 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

In this section, we will learn how to 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

First, use the code example below to upload the PDF files to the cloud:

The uploaded PDF files will therefore be accessible in the files section of your dashboard on the cloud.

Merge Multiple PDF into One Online using Node.js

Next, 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 Join Item in the File Info
  • Create the second JoinItem
  • Create the second item FileInfo
  • Provide the input file path for the 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
  • Lastly, 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 merged PDF file will be saved on the cloud using the code snippet above. You can download it using the following code sample:

How to Merge Multiple PDF files Pages in Node.js

You can quickly 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.

We also recommend that you read our Getting Started guide.

Moreover, groupdocs.cloud writes other blog articles about new topics. Please be aware of the latest updates.

Ask a question

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

FAQs

How do I combine multiple pages into one PDF using Node.js?

Please follow the Node.js code to know how to combine PDF files in windows, quickly and easily. You can visit the documentation for complete API details.

See Also

We suggest that you read the following articles to learn more: