In distributed organizations as well as in universities, various departments work on their own set of modules and produce data in the form of independent documents. Similar is the case when software is developed by multiple teams across the globe and during integration, the related system documents are also combined so that all the information becomes available in a single artifact. In order to combine the files, we may consider using some out-of-box solutions that incur installation and licensing costs and it also becomes quite difficult when we need to perform the document concatenation operation in bulk. In such scenarios, a programmatic solution is a viable solution and it gets even handy when you can perform all these PDF merge operations using REST APIs. Because no software download or installation is required. Simply make requests to the Cloud services and accomplish your requirements.
PDF Processing API
Aspose.PDF Cloud is a jewel in the crown. It empowers the users to create, edit and render PDF files to DOCX, PPTX, XLSX, PNG, JPEG, HTML, and much more formats. The beauty of this solution is a remarkable approach to accomplish the requirements with just a few code lines. Since it is developed on REST architecture, so it can be accessed with any programming language i.e. .NET, Java, PHP, Ruby, Rails, Python, jQuery, and many more. Use the API in Web, Desktop, Mobile, and cloud applications. In this article, we are focusing on Aspose.PDF Cloud utilization in Node.js programming language.
In order to facilitate our customers, we have created Aspose.PDF Cloud SDK for Node.js which is a wrapper around Aspose.PDF Cloud, so you get all the PDF files processing capabilities within the Node.js program. So the first step is to install the SDK on the system and the SDK is available for download from NPM or GitHub. We are going to discuss the installation of SDK through NPM. Please execute the following command on the command line terminal to perform the installation:
npm i asposepdfcloud
In order to use the Cloud APIs, you need to have an account subscription because only authorized persons can have access to the REST APIs as well as the documents stored in cloud storage. The subscription is free and you can perform up to 150 free document processing requests. For subscription, please visit Aspose.Cloud dashboard. If you have GitHub or Google account, simply Sign Up. Otherwise, click on the Create a new Account button and provide the required information. Now login to the dashboard using credentials and expand the Applications section from the dashboard and scroll down towards the Client Credentials section to see Client ID and Client Secret details.
Combine PDF files in Node.js
The following section explains the steps on how to concatenate the PDF files using Node.js
- Create string variables defining Client ID and Client Secret details
- The next step is to create an instance of PdfApi while passing Client ID and Client Secret as arguments
- Specify the name of input PDF files (already available on Cloud storage)
- Finally, call the postAppendDocument(…) method which takes input PDF file, name of PDF file to be appended to first PDF and From and To page number of second PDF to be merged into first PDF
Merge PDF files using cURL command
The cURL commands also provide the leverage to access REST APIs through the command line terminal and since Aspose.PDF Cloud is also developed on REST architecture, so we can also access it using the cURL commands. Therefore, we can also use the cURL command to merge the PDF files. But, before we proceed with the PDF merge operation, we need to first generate a JWT access token based on Client ID and Client Secret details because the APIs are only accessed by authorized persons.
curl -v "https://api.aspose.cloud/connect/token" \ -X POST \ -d "grant_type=client_credentials&client_id=718e4235-8866-4ebe-bff4-f5a14a4b6466&client_secret=388e864b819d8b067a8b1cb625a2ea8e" \ -H "Content-Type: application/x-www-form-urlencoded" \ -H "Accept: application/json"
The following cURL command concatenates pages 3 to 5 of the second PDF file to the first PDF and the resultant PDF is saved on Cloud storage.
curl -v -X POST "https://api.aspose.cloud/v3.0/pdf/PdfWithTable(1).pdf/appendDocument?appendFile=Springer-Ebooks-1.pdf&startPage=3&endPage=5" \ -H "accept: application/json" \ -H "authorization: Bearer <JWT Token>"
This article has explained the capabilities of Aspose.PDF Cloud for document concatenation. We have discussed the steps on how to combine PDF in Node.js programming language and also we have discussed the steps on how to accomplish the same requirement using the cURL command. The PDF manipulation API is much more capable and further details can be found over Aspose.PDF Cloud Features. The complete source code is also available for download over GitHub.
We recommend you to visit following links for further information on