merge PDF files

Learn how to append PDF files using .NET REST API.

In a digitally dominated world, the ability to efficiently merge and concatenate PDF files is more than just a convenient feature. The PDFs are renowned for their universality and consistent formatting, so they serve as the go-to format for various professional and personal purposes. However, we may have a requirement to merge chapters of a book, integrate different sections of a report, or combining receipts into a single expense report. This article delves into the pressing need for merging PDF files where we are not just combining the whole documents but based on our preference/selection, we are going to append selected pages between two PDF files using .NET Cloud SDK.

.NET Cloud SDK to Append PDF Files

Appending PDF files is a breeze with the Aspose.PDF Cloud SDK for .NET. This robust .NET Cloud SDK provides a seamless and efficient approach to merge and concatenate PDFs, enabling you to effortlessly combine multiple PDF files into a single, cohesive document. You also get the leverage to specify the location where pages will be appended, providing you a full flexibility and control over document management. Therefore, with the use of this SDK, you’ll master the art of PDF file appending, enhancing document management and presentation.

The first step is to add the SDK reference in our project and for that purpose, please search Aspose.PDF-Cloud in NuGet packages manager inside Visual Studio IDE and click the Add Package button.

You also need to obtain your client credentials from cloud dashboard. In case you do not have an existing account, simply create a free account by following the instructions specified over quick start.

Append PDF Files using C# .NET

Please follow the instructions given below to and streamline your PDF file append operation using C# .NET.

merge pdf files

Preview of Append PDF files operation.

Given below are quick details regarding above stated code snippet.

PdfApi pdfApi = new PdfApi(clientSecret, clientID);

Firstly, create an object of PdfApi class while passing client credentials as input arguments.

pdfApi.PostAppendDocument("input.pdf", "FileToAppend.pdf", 1,3);

Now, call the API to append the pages from index 1 to 3 of the second file to the first document. The input files must be already available in cloud storage.

Merge PDFs using cURL Commands

Appending PDF files using Aspose.PDF Cloud and cURL commands is a straightforward and efficient process. Aspose.PDF Cloud API allows you to merge multiple PDF files into a single, cohesive document with ease. By utilizing cURL commands, you can send HTTP requests to the Aspose.PDF Cloud API, initiating the PDF append operation seamlessly. Furthermore, the simplicity and effectiveness of cURL commands in conjunction with Aspose.PDF Cloud make this approach an accessible and powerful way to achieve PDF file append, enhancing document organization and workflow efficiency.

The first step in this approach is the generation of a JWT access token. So, please execute the following command:

curl -v "https://api.aspose.cloud/connect/token" \
 -X POST \
 -d "grant_type=client_credentials&client_id=163c02a1-fcaa-4f79-be54-33012487e783&client_secret=c71cfe618cc6c0944f8f96bdef9813ac" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -H "Accept: application/json"

Once a JWT token is generated, please execute the following command to append page 1, 2 and 3 from the second PDF to the first PDF file. After successful operation, the resultant PDF file is stored in cloud storage.

curl -v "https://api.aspose.cloud/v3.0/pdf/{sourcePDF}/appendDocument?appendFile={PDFtoAppend}&startPage=1&endPage=3" \
-X POST \
-H  "accept: application/json" \
-H  "authorization: Bearer {accessToken}" \
-d{}

Replace sourcePDF with the name of the first PDF to which pages need to be appended. Replace PDFtoAppend with the name of PDF file whose pages need to be appended and, accessToken with JWT access token generated above.

Conclusion

In conclusion, merging and appending PDF files are fundamental processes for efficient document management and presentation. We explored two powerful approaches to achieve this: utilizing the Aspose.PDF Cloud SDK for .NET and leveraging Aspose.PDF Cloud with cURL commands. Both approaches lead to a unified and organized PDF document, seamlessly merged to meet specific requirements. The choice between the two depends on individual project needs, technical expertise, and preferred integration methods, offering flexibility to cater to various scenarios.

We highly recommend visiting the following blogs: